-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
118683: sql: refactor IndexedVars and remove Used field r=mgartner a=mgartner #### sql: remove unused "source" parameter in planner.analyzeExpr The `source` parameter of `planner.analyzeExrp` was unused, so it has been removed. The `planner.resolveNames` function and the `planner.nameResolutionVisitor` field have also been removed as a result. Release note: None #### schemaexpr: refactor NameResolutionVisitor The `NameResolutionVisitor` is not used outside the `schemaexpr` package, so it has been unexported. Additionally, it no longer attempts to rebind indexed vars or normalized function names. Neither of these steps are necessary because this struct is only used to resolved column names to indexed vars for computed column and partial index expressions. Release note: None #### schemaexpr: rename select_name_resolution.go to name.go Release note: None #### sem/tree: add IndexedVarHelper.RebindTyped This commit splits `IndexedVarHelper.Rebind` into two functions, one to rebind untyped expressions, and one to rebind typed expressions. This is a mechanical change that will make subsequent changes easier. Release note: None #### sem/tree,execinfrapb: remove ivarBinder The `execinfrapb.ivarBinder` struct has been removed. In its place we use the `IndexedVarHelper.Rebind` method. I believe that the special behavior of `BindIfUnbound` where it does not bind an already bound indexed var is vestigial and unused. Therefore, that logic is not preserved. Release note: None #### sem/tree: remove IndexedVarHelper.IndexedVarUsed method The `IndexedVarHelper.IndexedVarUsed` method was only used in tests. It has been removed. Tests that used it now track usage of indexed vars in their own implementation of the `IndexedVarContainer` interface. Release note: None #### sem/tree: remove IndexedVar.Used field The `IndexedVar.Used` field has been removed because it was no longer used. This shrinks the size of the `IndexedVar` struct from 40 bytes to 32 bytes, a 20% reduction. This reduces allocate memory, especially for workloads with queries involving many columns. Informs #117546 Release note: None Co-authored-by: Marcus Gartner <[email protected]>
- Loading branch information
Showing
23 changed files
with
152 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2016 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
// | ||
// This file implements the select code that deals with column references | ||
// and resolving column names in expressions. | ||
|
||
package schemaexpr | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree" | ||
) | ||
|
||
// nameResolutionVisitor is a tree.Visitor implementation used to resolve column | ||
// names in an expression as indexed vars. | ||
type nameResolutionVisitor struct { | ||
err error | ||
iVarHelper tree.IndexedVarHelper | ||
resolver colinfo.ColumnResolver | ||
} | ||
|
||
var _ tree.Visitor = &nameResolutionVisitor{} | ||
|
||
// VisitPre implements tree.Visitor. | ||
func (v *nameResolutionVisitor) VisitPre(expr tree.Expr) (recurse bool, newNode tree.Expr) { | ||
if v.err != nil { | ||
return false, expr | ||
} | ||
|
||
switch t := expr.(type) { | ||
case *tree.UnresolvedName: | ||
vn, err := t.NormalizeVarName() | ||
if err != nil { | ||
v.err = err | ||
return false, expr | ||
} | ||
return v.VisitPre(vn) | ||
|
||
case *tree.ColumnItem: | ||
_, err := colinfo.ResolveColumnItem(context.Background(), &v.resolver, t) | ||
if err != nil { | ||
v.err = err | ||
return false, expr | ||
} | ||
|
||
colIdx := v.resolver.ResolverState.ColIdx | ||
ivar := v.iVarHelper.IndexedVar(colIdx) | ||
return true, ivar | ||
} | ||
return true, expr | ||
} | ||
|
||
// VisitPost implements tree.Visitor. | ||
func (*nameResolutionVisitor) VisitPost(expr tree.Expr) tree.Expr { return expr } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.