-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
roachtest: sqlsmith: index out of range in schema changer with CREATE FUNCTION #104242
Comments
Here's a reduced reproduction: CREATE TABLE t (a INT);
CREATE TYPE typ AS ENUM ('foo');
CREATE FUNCTION f() RETURNS INT LANGUAGE SQL AS $$
SELECT 1 FROM t WHERE NULL::typ IN ()
$$; It reproduces on v23.1.2 and master. It does not reproduce on v22.2.2. Stack trace:
|
Passing to SQL Foundations to take a look. Feel free to pass back if you think this belongs to SQL Queries. |
Seems similar to #103541. We didn't have a repro before, so we can take a closer look now. |
It looks like the issue is with resolving the type name @Xiang-Gu can you take a look at this panic? If you need help, perhaps you can work with @chengxiong-ruan since he's been in this area recently. |
@Xiang-Gu this failure is pretty noisy. Is there a way we can prevent our random SQL tests from hitting this until a fix is merged? Is there something we can do that's less heavy-handed then disabling |
looking at it |
When we parse a This difference can cause Unsurprisingly, for the provided repro, the legacy schema changer also panics with the same error but under a different code path (whenever This issue overall seems to be a minor inconvenience of a few moving pieces: how we chose to treat function body as a string in a As for fixes, I don't think I am going to touch any parser code (although it might seem tempting to fix the root cause; I am not familiar with sql.y and sql.go and I felt this is not easy). Instead, I am going to overwrite |
It seems rather straightforward to fix the declarative schema changer case. Namely, in declarative schema changer, we cloned and operated a new annotation on the
It will suffice if we squeezed in some logic here to parse the function body and overwrite statement.NumAnnotations to be max(statement.NumAnnotations, max(funcBodyStmt.NumAnnotations within funcBodyStmts)) , and thus initializing a "long" enough annotations slice.
What puzzles me now is how to fix the legacy schema changer case where things seems to be more "coupled". Namely, I learned that annotations are stored in |
I will think of it a bit more, but I will fine for short-term mitigation by fixing only the declarative schema changer to silence those test failures. |
Fixes cockroachdb#104242 Release note (bug fix): Fixed a bug when creating UDFs whose body contains a ShortCast operator. E.g. `CREATE FUNCTION f() RETURNS INT LANGUAGE SQL AS $$ SELECT 1 FROM t WHERE NULL::typ IN () $$;`
I'm not sure this works - even if it prevents an out-of-bounds error, there will be multiple expressions (from different UDF body statements as well as the parent query) that reference the same annotation index, which stores the resolved object name for an unresolved name in the AST. I think the way we save only the @Xiang-Gu does that sound reasonable? It sounds like it might be a simpler fix than modifying both schema changer paths. |
roachtest.sqlsmith/setup=rand-tables/setting=no-mutations failed with artifacts on master @ bf25b7bf93a6b8e57557813957da263389796bb4:
Parameters:
ROACHTEST_cloud=gce
,ROACHTEST_cpu=4
,ROACHTEST_encrypted=false
,ROACHTEST_ssd=0
Help
See: roachtest README
See: How To Investigate (internal)
This test on roachdash | Improve this report!
Jira issue: CRDB-28424
The text was updated successfully, but these errors were encountered: