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

[memo] RequiredIndex interface #2238

Merged
merged 2 commits into from
Jan 4, 2024
Merged

[memo] RequiredIndex interface #2238

merged 2 commits into from
Jan 4, 2024

Conversation

max-hoffman
Copy link
Contributor

Some table nodes need to be executed as IndexScans with mandatory filters. The new interface makes this transparent to join planning.

re: dolthub/dolt#7256

Some table nodes need to be executed as IndexScans with mandatory
filters. The new interface makes this transparent to join planning.
Copy link
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good solution just a few comments

// IndexRequired tables cannot be executed without index lookups on certain
// columns. Join planning uses this interface to maintain plan correctness
// for these nodes
type IndexRequired interface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good interface, good name

p.reqIdxCols = rel.Child.RelProps.reqIdxCols
case *Filter:
p.reqIdxCols = rel.Child.RelProps.reqIdxCols
default:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No empty default

@@ -167,6 +170,26 @@ func (m *Memo) MemoizeLookupJoin(grp, left, right *ExprGroup, op plan.JoinType,
return grp
}

func (m *Memo) MemoizeHashJoin(grp *ExprGroup, join *JoinBase, toExpr, fromExpr []sql.Expression) *ExprGroup {
if join.Right.RelProps.reqIdxCols.Len() > 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment about this logic would help

sql/memo/memo.go Outdated
@@ -143,6 +143,9 @@ func (m *Memo) MemoizeInnerJoin(grp, left, right *ExprGroup, op plan.JoinType, f
}

func (m *Memo) MemoizeLookupJoin(grp, left, right *ExprGroup, op plan.JoinType, filter []sql.Expression, lookup *IndexScan) *ExprGroup {
if left.RelProps.reqIdxCols.Union(right.RelProps.reqIdxCols).Difference(lookup.Index.set).Len() > 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment about this logic would help

@max-hoffman max-hoffman merged commit dcf9acb into main Jan 4, 2024
7 checks passed
@max-hoffman max-hoffman deleted the max/required-index branch January 4, 2024 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants