Skip to content
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

sql: SHOW JOBS SELECT query should not see the SHOW JOBS columns #121284

Closed
RaduBerinde opened this issue Mar 28, 2024 · 2 comments
Closed

sql: SHOW JOBS SELECT query should not see the SHOW JOBS columns #121284

RaduBerinde opened this issue Mar 28, 2024 · 2 comments
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@RaduBerinde
Copy link
Member

RaduBerinde commented Mar 28, 2024

The following statement runs when it shouldn't:

SHOW JOBS SELECT job_id FROM system.jobs;

system.jobs does not have a job_id column. SHOW JOBS produces a job_id column, so this is handled like a correlated subquery.

This is not surprising because internally it gets rewritten as a subquery:

whereClause = fmt.Sprintf(`WHERE job_id in (%s)`, n.Jobs.String())

The fix might be as easy as changing (%s) to [%s] here. As a reminder [ query ] is syntactic sugar for a top-level WITH x AS query. It might be cleaner to just generate the top-level WITH instead of using [ .. ] though.

Jira issue: CRDB-37172

@RaduBerinde RaduBerinde added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Mar 28, 2024
@blathers-crl blathers-crl bot added the T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) label Mar 28, 2024
@RaduBerinde
Copy link
Member Author

plan:

EXPLAIN (VERBOSE) SHOW JOBS SELECT job_id FROM system.jobs;

  • cross join (inner)
  │ columns: (job_id, job_type, description, statement, user_name, status, running_status, created, started, finished, modified, fraction_completed, error, coordinator_id, trace_id, last_run, next_run, num_runs, execution_errors)
  │ estimated row count: 990 (missing stats)
  │
  ├── • filter
  │   │ columns: (job_id, job_type, description, statement, user_name, status, running_status, created, started, finished, modified, fraction_completed, error, coordinator_id, trace_id, last_run, next_run, num_runs, execution_errors)
  │   │ estimated row count: 990 (missing stats)
  │   │ filter: job_id IS DISTINCT FROM CAST(NULL AS INT8)
  │   │
  │   └── • virtual table
  │         columns: (job_id, job_type, description, statement, user_name, status, running_status, created, started, finished, modified, fraction_completed, error, coordinator_id, trace_id, last_run, next_run, num_runs, execution_errors)
  │         estimated row count: 1,000 (missing stats)
  │         table: jobs@primary
  │
  └── • scan
        columns: ()
        estimated row count: 1 (missing stats)
        table: jobs@jobs_job_type_idx
        spans: LIMITED SCAN
        limit: 1

@rafiss
Copy link
Collaborator

rafiss commented Mar 29, 2024

This appears to duplicate #100996

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
No open projects
Status: Done
Development

No branches or pull requests

2 participants