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: typing of multi-row subqueries is confusing #21124

Open
petermattis opened this issue Dec 29, 2017 · 4 comments
Open

sql: typing of multi-row subqueries is confusing #21124

petermattis opened this issue Dec 29, 2017 · 4 comments
Labels
A-sql-typing SQLtype inference, typing rules, type compatibility. C-cleanup Tech debt, refactors, loose ends, etc. Solution not expected to significantly change behavior. T-sql-queries SQL Queries Team

Comments

@petermattis
Copy link
Collaborator

petermattis commented Dec 29, 2017

Multi-row subqueries are currently typed as tuple{U}. This plays nicely with the type checking code which can thus treat a multi-row subquery very similarly to a tuple, but is wrong semantically. The subquery has a variable number of elements, while tuple{U} is specifying a fixed length tuple with 1 element. That this works is due to misuse of the tuple type in the type checking code. See typeCheckSubqueryWithIn.

Instead of using tuple{U}, multi-row subqueries should be typed with a variable length type such as table{U} or vtuple{U} (variable tuple). The existing types.TTable type seems to fit the bill, though there is mild concern due to the existing usage of that type for set-returning-functions (e.g. generate_series).

In order to change the type of multi-row subqueries, the type checking code for IN, NOT IN, ALL, SOME, ANY and ARRAY needs to change. This is currently non-trivial. For example, there currently exists an overload for <tuple> IN <tuple>. Would we also need an overload for <tuple> IN <table>? There are also bits of special type checking code which look for types.TTuple which would need to be generalized. See #21123 for additional commentary on the type checking code.

Cc @nvanbenschoten, @knz

Jira issue: CRDB-5899

@RaduBerinde
Copy link
Member

See #21273 for a related issue in NewTypedComparisonExpr* code.

@knz knz added C-cleanup Tech debt, refactors, loose ends, etc. Solution not expected to significantly change behavior. A-sql-typing SQLtype inference, typing rules, type compatibility. labels May 9, 2018
@knz knz added this to Triage in (DEPRECATED) SQL Front-end, Lang & Semantics via automation May 9, 2018
@knz knz moved this from Triage to Backlog in (DEPRECATED) SQL Front-end, Lang & Semantics May 14, 2018
@petermattis petermattis removed this from the Later milestone Oct 5, 2018
@jordanlewis jordanlewis moved this from Triage to Lower priority backlog in [DEPRECATED] Old SQLExec board. Don't move stuff here Apr 27, 2019
@asubiotto asubiotto added this to Triage in BACKLOG, NO NEW ISSUES: SQL Optimizer via automation Apr 3, 2020
@asubiotto
Copy link
Contributor

@RaduBerinde this seems like a planning issue, moving to your project.

@RaduBerinde
Copy link
Member

Leaving some notes about this:

@RaduBerinde RaduBerinde moved this from Triage to Lower Priority Backlog in BACKLOG, NO NEW ISSUES: SQL Optimizer Apr 3, 2020
@RaduBerinde RaduBerinde moved this from Lower Priority Backlog to Infrastructure & performance in BACKLOG, NO NEW ISSUES: SQL Optimizer Apr 18, 2020
@jlinder jlinder added the T-sql-queries SQL Queries Team label Jun 16, 2021
@github-actions
Copy link

We have marked this issue as stale because it has been inactive for
18 months. If this issue is still relevant, removing the stale label
or adding a comment will keep it active. Otherwise, we'll close it in
10 days to keep the issue queue tidy. Thank you for your contribution
to CockroachDB!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 9, 2023
BACKLOG, NO NEW ISSUES: SQL Optimizer automation moved this from Infrastructure & performance to Done Oct 9, 2023
@yuzefovich yuzefovich reopened this May 2, 2024
BACKLOG, NO NEW ISSUES: SQL Optimizer automation moved this from Done to Triage May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-typing SQLtype inference, typing rules, type compatibility. C-cleanup Tech debt, refactors, loose ends, etc. Solution not expected to significantly change behavior. T-sql-queries SQL Queries Team
Projects
Status: Backlog
Development

No branches or pull requests

6 participants