sql: unwanted correlation hides semantic errors in delegated SHOW statements #100996
Labels
C-bug
Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.
T-sql-queries
SQL Queries Team
Describe the problem
I typed the following INVALID query while investigating #99200:
(The query is invalid because
system.jobs
does not have ajob_id
column.)Observe: The query runs to completion (and returns bogus results).
The reason for this behavior is that under the hood
SHOW JOBS XXX
expands intoSELECT ... FROM crdb_internal.jobs WHERE job_id IN (XXX)
So in the example above we get:
And then the query correlation rules apply: because
job_id
in the sub-query doesn't exist insystem.jobs
, it is picked from the outer scope (fromcrdb_internal.jobs
). So we get effectively a cross-join between the two tables.Expected behavior
Every time one of the "delegate" functions creates SQL syntax using a parameter that is also a "select clause", we need to be careful to disable the query correlation rules.
For example, in the above this can be achieved via
which, in this case, properly errors out.
We would also need to audit the other delegate functions accordingly.
Jira issue: CRDB-26737
The text was updated successfully, but these errors were encountered: