Skip to content

Commit

Permalink
fixup! opt: fixup CTE stats on placeholder queries
Browse files Browse the repository at this point in the history
Not sure if this is better/necessary/correct...
  • Loading branch information
cucaroach committed Mar 27, 2023
1 parent 9d3d8b3 commit 41518e5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/sql/opt/norm/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/opt"
"github.com/cockroachdb/cockroach/pkg/sql/opt/cat"
"github.com/cockroachdb/cockroach/pkg/sql/opt/memo"
"github.com/cockroachdb/cockroach/pkg/sql/opt/props"
"github.com/cockroachdb/cockroach/pkg/sql/opt/props/physical"
_ "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins" // register all builtins in builtins:init() for memo package
"github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtinsregistry"
Expand Down Expand Up @@ -358,16 +357,18 @@ func (f *Factory) AssignPlaceholders(from *memo.Memo) (err error) {
if rcte, ok := e.(*memo.RecursiveCTEExpr); ok {
newInitial := f.CopyAndReplaceDefault(rcte.Initial, replaceFn).(memo.RelExpr)
if newInitial != rcte.Initial {
newCardinality := newInitial.Relational().Cardinality.Union(rcte.Recursive.Relational().Cardinality)
newBinding := f.ConstructFakeRel(&memo.FakeRelPrivate{
Props: MakeBindingPropsForRecursiveCTE(
props.AnyCardinality, rcte.Binding.Relational().OutputCols, newInitial.Relational().Statistics().RowCount)})
newCardinality, rcte.Binding.Relational().OutputCols, newInitial.Relational().Statistics().RowCount)})
if id := rcte.WithBindingID(); id != 0 {
f.Metadata().AddWithBinding(id, newBinding)
}
newRecursive := f.CopyAndReplaceDefault(rcte.Recursive, replaceFn).(memo.RelExpr)
return f.ConstructRecursiveCTE(
newBinding,
newInitial,
f.invokeReplace(rcte.Recursive, replaceFn).(memo.RelExpr),
newRecursive,
&rcte.RecursiveCTEPrivate,
)
}
Expand Down

0 comments on commit 41518e5

Please sign in to comment.