Throw an error if there is a RangeTblEntry that is not assigned an RTE identity. (#6295)

* Fix issue : 6109 Segfault or (assertion failure) is possible when using a SQL function

* DESCRIPTION: Ensures disallowing the usage of SQL functions referencing to a distributed table and prevents a segfault.
Using a SQL function may result in segmentation fault in some cases.
This change fixes the issue by throwing an error message when a SQL function cannot be handled.

Fixes #6109.

* DESCRIPTION: Ensures disallowing the usage of SQL functions referencing to a distributed table and prevents a segfault.
Using a SQL function may result in segmentation fault in some cases. This change fixes the issue by throwing an error message when a SQL function cannot be handled.

Fixes #6109.

Co-authored-by: Emel Simsek <emel.simsek@microsoft.com>
pull/6288/head^2
Emel Şimşek 2022-09-06 16:46:41 +03:00 committed by GitHub
parent 69726648ab
commit 6f06ff78cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 2 deletions

View File

@ -559,9 +559,26 @@ int
GetRTEIdentity(RangeTblEntry *rte)
{
Assert(rte->rtekind == RTE_RELATION);
Assert(rte->values_lists != NIL);
/*
* Since SQL functions might be in-lined by standard_planner,
* we might miss assigning an RTE identity for RangeTblEntries
* related to SQL functions. We already have checks in other
* places to throw an error for SQL functions but they are not
* sufficient due to function in-lining; so here we capture such
* cases and throw an error here.
*/
if (list_length(rte->values_lists) != 2)
{
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot perform distributed planning on this "
"query because parameterized queries for SQL "
"functions referencing distributed tables are "
"not supported"),
errhint("Consider using PL/pgSQL functions instead.")));
}
Assert(IsA(rte->values_lists, IntList));
Assert(list_length(rte->values_lists) == 2);
return linitial_int(rte->values_lists);
}

View File

@ -320,6 +320,9 @@ INSERT INTO test_parameterized_sql VALUES(1, 1);
SELECT * FROM test_parameterized_sql_function(1);
ERROR: cannot perform distributed planning on this query because parameterized queries for SQL functions referencing distributed tables are not supported
HINT: Consider using PL/pgSQL functions instead.
SELECT (SELECT 1 FROM test_parameterized_sql limit 1) FROM test_parameterized_sql_function(1);
ERROR: cannot perform distributed planning on this query because parameterized queries for SQL functions referencing distributed tables are not supported
HINT: Consider using PL/pgSQL functions instead.
SELECT test_parameterized_sql_function_in_subquery_where(1);
ERROR: could not create distributed plan
DETAIL: Possibly this is caused by the use of parameters in SQL functions, which is not supported in Citus.

View File

@ -144,6 +144,9 @@ INSERT INTO test_parameterized_sql VALUES(1, 1);
-- all of them should fail
SELECT * FROM test_parameterized_sql_function(1);
SELECT (SELECT 1 FROM test_parameterized_sql limit 1) FROM test_parameterized_sql_function(1);
SELECT test_parameterized_sql_function_in_subquery_where(1);
-- postgres behaves slightly differently for the following