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: name resolution/expansion is performed in-place in the AST #22847

Open
knz opened this issue Feb 20, 2018 · 2 comments
Open

sql: name resolution/expansion is performed in-place in the AST #22847

knz opened this issue Feb 20, 2018 · 2 comments
Labels
A-sql-optimizer SQL logical planning and optimizations. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-queries SQL Queries Team

Comments

@knz
Copy link
Contributor

knz commented Feb 20, 2018

The facilities ResolveExistingName / ResolveTargetName / ColumnItemResolver (previously: QualifyWithDatabaseName, findColumn) edit the AST node in-place (TableName or ColumnItem).

The result of this name resolution however are context-dependent on session variables and the current schema in KV: the current database, the search path, and the descriptors currently visible.

Therefore it is unsafe + incorrect to reuse the modified AST across multiple executes.

The fix for this must either avoid modifying the AST in-place, or ensure the modified AST is not reused.

cc @jordanlewis

Jira issue: CRDB-5841

@knz knz added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Feb 20, 2018
@knz knz added this to the 2.0 milestone Feb 20, 2018
@knz knz self-assigned this Feb 20, 2018
@jordanlewis jordanlewis modified the milestones: 2.0, 2.1 Mar 13, 2018
@knz knz added the A-sql-optimizer SQL logical planning and optimizations. label Apr 28, 2018
@nstewart nstewart added the S-3-erroneous-edge-case Database produces or stores erroneous data without visible error/warning, in rare edge cases. label Sep 18, 2018
@knz knz modified the milestones: 2.1, 2.2 Oct 5, 2018
@knz knz removed their assignment Oct 5, 2018
@RaduBerinde RaduBerinde self-assigned this Apr 1, 2019
@RaduBerinde RaduBerinde modified the milestones: 19.1, 19.2 Apr 1, 2019
RaduBerinde added a commit to RaduBerinde/cockroach that referenced this issue May 13, 2019
This change adds infrastructure for annotating AST nodes. Only certain
nodes can be annotated (currently `UnresolvedObjectName`). The parser
sets up annotation indices for these nodes, and the annotations are
stored in a separate Annotation container. The annotations will allow
us to stop modifying the AST during type and semantic checking.

The annotation for an `UnresolvedObjectName` will contain the resolved
`*TableName`.

See cockroachdb#34240 and cockroachdb#22847 for more context.

Release note: None
RaduBerinde added a commit to RaduBerinde/cockroach that referenced this issue May 15, 2019
This change adds infrastructure for annotating AST nodes. Only certain
nodes can be annotated (currently `UnresolvedObjectName`). The parser
sets up annotation indices for these nodes, and the annotations are
stored in a separate Annotation container. The annotations will allow
us to stop modifying the AST during type and semantic checking.

The annotation for an `UnresolvedObjectName` will contain the resolved
`*TableName`.

See cockroachdb#34240 and cockroachdb#22847 for more context.

Release note: None
craig bot pushed a commit that referenced this issue May 15, 2019
37484: sql: add AST annotations r=RaduBerinde a=RaduBerinde

#### sql: add AST annotations

This change adds infrastructure for annotating AST nodes. Only certain
nodes can be annotated (currently `UnresolvedObjectName`). The parser
sets up annotation indices for these nodes, and the annotations are
stored in a separate Annotation container. The annotations will allow
us to stop modifying the AST during type and semantic checking.

The annotation for an `UnresolvedObjectName` will contain the resolved
`*TableName`.

See #34240 and #22847 for more context.

Release note: None

#### sql: use UnresolvedObjectName in AlterTable

Change AlterTable to contain an `UnresolvedObjectName`.

Release note: None


Co-authored-by: Radu Berinde <[email protected]>
@github-actions
Copy link

github-actions bot commented Jun 7, 2021

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
5 days to keep the issue queue tidy. Thank you for your contribution
to CockroachDB!

@knz knz removed this from the 20.1 milestone Jun 7, 2021
@RaduBerinde RaduBerinde removed the S-3-erroneous-edge-case Database produces or stores erroneous data without visible error/warning, in rare edge cases. label Jun 8, 2021
@RaduBerinde
Copy link
Member

Removing the erroneous-edge-case label because there are no known correctness issues - we don't reuse the AST because of these modifications. Leaving the issue open because we would like to stop making these modifications and reuse ASTs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-optimizer SQL logical planning and optimizations. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-queries SQL Queries Team
Projects
Status: Cold Storage
Development

No branches or pull requests

5 participants