-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
udf: select * in a udf combined with edited table can cause crashes #86070
Comments
This is a good catch and interesting...In postgres if you use their early binding syntax, it still works: postgres=# create table tt(a int);
CREATE TABLE
postgres=# create function ff() returns int language sql
postgres-# begin atomic
postgres-# select * from tt;
postgres-# end;
CREATE FUNCTION
postgres=# alter table tt add column b int;
ALTER TABLE
postgres=# insert into tt values (2,1);
INSERT 0 1
postgres=# select ff();
ff
----
2
(1 row) I'm confused what should we do here for the long term. I think in the short term we should prevent the function from being broken. Either disallow the table from being mutated, or we should revalidate the function body when doing the type checking to throw out a better error. |
This is also a good corner case to consider when we're going to design function body rewritting. |
postgres resolves the SELECT n.nspname AS schema
,proname AS fname
,proargnames AS args
,t.typname AS return_type
,d.description
,pg_get_functiondef(p.oid) as definition
-- ,CASE WHEN NOT p.proisagg THEN pg_get_functiondef(p.oid)
-- ELSE 'pg_get_functiondef() can''t be used with aggregate functions'
-- END as definition
FROM pg_proc p
JOIN pg_type t
ON p.prorettype = t.oid
LEFT OUTER
JOIN pg_description d
ON p.oid = d.objoid
LEFT OUTER
JOIN pg_namespace n
ON n.oid = p.pronamespace
WHERE NOT p.prokind = 'a' and p.proname = 'f';
schema | fname | args | return_type | description | definition
--------+-------+------+-------------+-------------+------------------------------------------------
public | f | {i} | int4 | | CREATE OR REPLACE FUNCTION public.f(i integer)+
| | | | | RETURNS integer +
| | | | | LANGUAGE sql +
| | | | | IMMUTABLE +
| | | | | BEGIN ATOMIC +
| | | | | SELECT t.i +
| | | | | FROM sc.t +
| | | | | WHERE (f.i > t.i); +
| | | | | END +
| | | | | |
Interestingly we don't support |
I'm planning on trying to fix this for 22.2. |
Labelling as a release blocker. A fix to prevent node crashes in this case should be trivial. |
I think we can disable support for the |
Fixes cockroachdb#86070 Release note (sql change): Star expressions, e.g., `SELECT * FROM ...` are no longer allowed in statements in user-defined functions. They were allowed in early betas of v22.2 from v22.2.0-beta.1 to v22.2.0-beta.4, but have been disallowed because they do not behave correctly. Issue cockroachdb#90080 tracks re-enabling star expressions in UDFs.
This commit disallows star expressions in UDF bodies (see the release note below). It also fixes an error message returned when trying to create a view that references non-existent columns that incorrectly mentioned star expressions. Fixes cockroachdb#86070 Release note (sql change): Star expressions, e.g., `SELECT * FROM ...` are no longer allowed in statements in user-defined functions. They were allowed in early betas of v22.2 from v22.2.0-beta.1 to v22.2.0-beta.4, but have been disallowed because they do not behave correctly. Issue cockroachdb#90080 tracks re-enabling star expressions in UDFs.
90085: sql: disallow star expressions in UDF bodies r=mgartner a=mgartner This commit disallows star expressions in UDF bodies (see the release note below). It also fixes an error message returned when trying to create a view that references non-existent columns that incorrectly mentioned star expressions. Fixes #86070 Release note (sql change): Star expressions, e.g., `SELECT * FROM ...` are no longer allowed in statements in user-defined functions. They were allowed in early betas of v22.2 from v22.2.0-beta.1 to v22.2.0-beta.4, but have been disallowed because they do not behave correctly. Issue #90080 tracks re-enabling star expressions in UDFs. Co-authored-by: Marcus Gartner <[email protected]>
This commit disallows star expressions in UDF bodies (see the release note below). It also fixes an error message returned when trying to create a view that references non-existent columns that incorrectly mentioned star expressions. Fixes #86070 Release note (sql change): Star expressions, e.g., `SELECT * FROM ...` are no longer allowed in statements in user-defined functions. They were allowed in early betas of v22.2 from v22.2.0-beta.1 to v22.2.0-beta.4, but have been disallowed because they do not behave correctly. Issue #90080 tracks re-enabling star expressions in UDFs.
This commit disallows star expressions in UDF bodies (see the release note below). It also fixes an error message returned when trying to create a view that references non-existent columns that incorrectly mentioned star expressions. Fixes #86070 Release note (sql change): Star expressions, e.g., `SELECT * FROM ...` are no longer allowed in statements in user-defined functions. They were allowed in early betas of v22.2 from v22.2.0-beta.1 to v22.2.0-beta.4, but have been disallowed because they do not behave correctly. Issue #90080 tracks re-enabling star expressions in UDFs.
It's possible to use
SELECT *
within a UDF, which seems to cause issues after editing the table that's beingSELECT *
'd from. In other contexts we just banSELECT *
.For the record, the equivalent sequence in Postgres does this:
Jira issue: CRDB-18552
The text was updated successfully, but these errors were encountered: