Skip to content

Commit 9e6d9a4

Browse files
ayushdshYashneet Vinayak
authored andcommitted
Fix: Rectified dialect check in ENRGetSystableScan function to also check for the conn_type (#632)
* Fix: Rectified dialect check in ENRGetSystableScan function to also check for the conn_type In ENRGetSystableScan, if the dialect is not TSQL_DIALECT and there is a scan initiated for a catalog (other than Sequence), we return false i.e. the tuple being scanned for does not exist in ENR. But this is not reliable in case this scan is initiated from a PG function since the dialect then would be PG_DIALECT and the scan in ENR would return false, even though the actual tuple being searched for is in ENR (in case it's a T-SQL temp table). This results in a "could not open a relation" error since the tuple also does not exist in pg_catalog. Task: BABEL-6099 Signed-off-by: Ayush Shah <[email protected]>
1 parent 900adb9 commit 9e6d9a4

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/backend/utils/misc/queryenvironment.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "catalog/catalog.h"
3333
#include "catalog/dependency.h"
3434
#include "catalog/indexing.h"
35+
#include "catalog/namespace.h"
3536
#include "catalog/pg_authid.h"
3637
#include "catalog/pg_collation.h"
3738
#include "catalog/pg_opclass.h"
@@ -421,14 +422,22 @@ bool ENRGetSystableScan(Relation rel, Oid indexId, int nkeys, ScanKey key, List
421422

422423
Oid reloid = RelationGetRelid(rel);
423424

424-
if (sql_dialect != SQL_DIALECT_TSQL)
425+
/*
426+
* We should allow ENR scans for T_SQL dialect as well as
427+
* PG dialect from TDS endpoint.
428+
* Because there are cases where dialect is set to temporarily to
429+
* PG when executing PG functions and it tries to scan ENRs.
430+
*
431+
* Note: Due to this condition, scanning for ENR temp tables
432+
* from PG endpoint and in PG dialect will not work.
433+
*/
434+
if (sql_dialect != SQL_DIALECT_TSQL && !(is_bbf_tds_connection_hook && is_bbf_tds_connection_hook()))
425435
{
426436
/*
427-
* We cannot return false right away when sql_dialect is not TSQL.
428-
* There are cases when sql_dialect is temporarily set to PG when
429-
* executing PG functions such as nextval_internal() in the case of
430-
* identity sequence.
431-
*/
437+
* There are cases when sql_dialect is temporarily set to PG when
438+
* executing PG functions such as nextval_internal() in the case of
439+
* identity sequence.
440+
*/
432441
if (reloid != SequenceRelationId)
433442
return false;
434443

0 commit comments

Comments
 (0)