Commit 9cecf3b3 authored by craig[bot]'s avatar craig[bot]

Merge #50754

50754: opt: add indexed var for inverted column when execbuilding inverted joins r=rytaft a=rytaft

This commit fixes an issue identified in #50709 in which the `execbuilder`
code for building inverted joins was failing due to the lack of an indexed
var for the column indexed by the inverted index. The indexed var is
necessary since the inverted expression contains a reference to the inverted
column. This commit fixes the issue by including the column in the indexed var

This commit does not include a release note since this issue was introduced
a few days ago and has not been released.

Release note: None
Co-authored-by: default avatarRebecca Taft <[email protected]>
parents a55e6339 59286e4e
......@@ -1395,6 +1395,11 @@ func (b *Builder) buildInvertedJoin(join *memo.InvertedJoinExpr) (execPlan, erro
inputCols := join.Input.Relational().OutputCols
lookupCols := join.Cols.Difference(inputCols)
// Add the inverted column since it will be referenced in the inverted
// expression and needs a corresponding indexed var. It will be projected
// away below.
lookupOrdinals, lookupColMap := b.getColumns(lookupCols, join.Table)
allCols := joinOutputMap(input.outputCols, lookupColMap)
......@@ -1435,11 +1440,8 @@ func (b *Builder) buildInvertedJoin(join *memo.InvertedJoinExpr) (execPlan, erro
return execPlan{}, err
// Apply a post-projection if Cols doesn't contain all input columns.
if !inputCols.SubsetOf(join.Cols) {
return b.applySimpleProject(res, join.Cols, join.ProvidedPhysical().Ordering)
return res, nil
// Apply a post-projection to remove the inverted column.
return b.applySimpleProject(res, join.Cols, join.ProvidedPhysical().Ordering)
func (b *Builder) buildZigzagJoin(join *memo.ZigzagJoinExpr) (execPlan, error) {
......@@ -62,3 +62,20 @@ InitPut /Table/53/2/1153290940513779712/4/0 -> /BYTES/
InitPut /Table/53/2/1154047404446580736/4/0 -> /BYTES/
InitPut /Table/53/2/1154328879490400256/4/0 -> /BYTES/
InitPut /Table/53/3/1152921510042997845/4/0 -> /BYTES/
statement ok
k int primary key,
geom geometry
statement ok
k int primary key,
geom geometry,
INVERTED INDEX geom_index(geom)
query error Geospatial joins are not yet supported
SELECT ltable.k, rtable.k FROM ltable JOIN [email protected]_index ON ST_Intersects(ltable.geom, rtable.geom)]
......@@ -249,8 +249,8 @@ type Factory interface {
// The node produces the columns in the input and (unless join type is
// LeftSemiJoin or LeftAntiJoin) the lookupCols, ordered by ordinal. The ON
// condition can refer to these using IndexedVars. Note that lookupCols does
// not include the inverted column.
// condition can refer to these using IndexedVars. Note that lookupCols
// includes the inverted column.
joinType sqlbase.JoinType,
invertedExpr tree.TypedExpr,
......@@ -361,6 +361,10 @@ define InvertedJoinPrivate {
# the cat.Table.Index() method in order to fetch the cat.Index metadata.
Index IndexOrdinal
# InvertedCol is the inverted column in the index that is referenced by
# InvertedExpr.
InvertedCol ColumnID
# InputCol is the column (produced by the input) that will be bound to
# InvertedExpr and used to determine the keys to scan in the inverted
# index.
......@@ -1935,6 +1935,7 @@ func (c *CustomFuncs) GenerateGeoLookupJoins(
lookupJoin.Table = scanPrivate.Table
lookupJoin.Index = iter.IndexOrdinal()
lookupJoin.InvertedExpr = function
lookupJoin.InvertedCol = indexGeoCol
lookupJoin.InputCol = inputGeoCol
lookupJoin.Cols = indexCols.Union(inputProps.OutputCols)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment