Skip to content

Commit

Permalink
Mark table_constraints_internal() function as parallel safe and set c…
Browse files Browse the repository at this point in the history
…urrent_db_id for parallel workers (#3321)

The INFORMATION_SCHEMA_TSQL.TABLE_CONSTRAINTS_INTERNAL() function was recently introduced
but not marked as PARALLEL SAFE. This prevented the query optimizer from utilizing parallel
plans in queries involving this function, leading to suboptimal performance for certain operations.

By marking the function as PARALLEL SAFE, we enable the use of parallel query execution plans,
which can significantly improve performance for large datasets.

This commit also addresses the issue of empty result sets in queries joining with sys.db_id()
or sys.db_name() in Enforced Parallel Query mode by setting the current_db_id in addition to
current_db_name for parallel workers.

Task: BABEL-5427, BABEL-5504

Signed-off-by: Sumit Jaiswal [email protected]
  • Loading branch information
sumitj824 authored Dec 30, 2024
1 parent 6426975 commit da9d1da
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion contrib/babelfishpg_tsql/sql/information_schema_tsql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ BEGIN
OR has_any_column_privilege(r.oid, 'SELECT, INSERT, UPDATE, REFERENCES') );
END;
$$
LANGUAGE plpgsql STABLE;
LANGUAGE plpgsql STABLE PARALLEL SAFE;

/*
* TABLE_CONSTRAINTS view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ BEGIN
OR has_any_column_privilege(r.oid, 'SELECT, INSERT, UPDATE, REFERENCES') );
END;
$$
LANGUAGE plpgsql STABLE;
LANGUAGE plpgsql STABLE PARALLEL SAFE;

/*
* TABLE_CONSTRAINTS view
Expand Down
5 changes: 4 additions & 1 deletion contrib/babelfishpg_tsql/src/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void
set_cur_db_name_for_parallel_worker(const char* logical_db_name)
{
int len;
int16 db_id;

if (logical_db_name == NULL)
ereport(ERROR,
Expand All @@ -80,13 +81,15 @@ set_cur_db_name_for_parallel_worker(const char* logical_db_name)

Assert(len <= MAX_BBF_NAMEDATALEND);

if(!DbidIsValid(get_db_id(logical_db_name)))
db_id = get_db_id(logical_db_name);
if(!DbidIsValid(db_id))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_DATABASE),
errmsg("database \"%s\" does not exist", logical_db_name)));

strncpy(current_db_name, logical_db_name, MAX_BBF_NAMEDATALEND);
current_db_name[len] = '\0';
current_db_id = db_id;
}


Expand Down

0 comments on commit da9d1da

Please sign in to comment.