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

opt: use equalities to constrain inverted join prefix columns #58222

Merged
merged 1 commit into from
Dec 30, 2020

Conversation

mgartner
Copy link
Collaborator

Non-inverted prefix columns can now be constrained by equality
constraints to generate inverted joins. For example, an inverted join is
now generated for the following query:

CREATE TABLE a (a INT, j JSON)
CREATE TABLE b (b INT, j JSON, INVERTED INDEX (b, j))

SELECT * FROM a JOIN b ON b = a AND b.j @> a.j

Previously, only constant filters could constrain non-inverted prefix
columns.

Release note: None

@mgartner mgartner requested a review from a team as a code owner December 23, 2020 00:40
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm: Cool!

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @mgartner, @RaduBerinde, and @rytaft)


pkg/sql/opt/xform/join_funcs.go, line 484 at r1 (raw file):

		// Only calculate the left and right equality columns if there is a
		// multi-column inverted index.
		if numPrefixCols > 0 && leftEqCols == nil {

[nit] maybe add a eqColsCalculated bool, because ExtractJoinEqualityColumns can return nil


pkg/sql/opt/xform/join_funcs.go, line 497 at r1 (raw file):

		// constraints and computed column expressions.
		var constFilters memo.FiltersExpr
		for i, n := 0, numPrefixCols; i < n; i++ {

we don't need n n-ymore

Copy link
Collaborator

@rytaft rytaft left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 2 of 2 files at r1.
Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @mgartner)

@mgartner mgartner force-pushed the inverted-join-equality-cols branch from 67c6d0d to 426c4b3 Compare December 23, 2020 18:20
Copy link
Collaborator Author

@mgartner mgartner left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained


pkg/sql/opt/xform/join_funcs.go, line 484 at r1 (raw file):

Previously, RaduBerinde wrote…

[nit] maybe add a eqColsCalculated bool, because ExtractJoinEqualityColumns can return nil

Good catch. Done.


pkg/sql/opt/xform/join_funcs.go, line 497 at r1 (raw file):

Previously, RaduBerinde wrote…

we don't need n n-ymore

😆 Done.

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @rytaft)

@mgartner mgartner force-pushed the inverted-join-equality-cols branch from 426c4b3 to 48cc523 Compare December 29, 2020 02:55
@mgartner
Copy link
Collaborator Author

TFTRs!

bors r+

@craig
Copy link
Contributor

craig bot commented Dec 29, 2020

Build failed:

@mgartner
Copy link
Collaborator Author

bors r+

craig bot pushed a commit that referenced this pull request Dec 30, 2020
58222: opt: use equalities to constrain inverted join prefix columns r=mgartner a=mgartner

Non-inverted prefix columns can now be constrained by equality
constraints to generate inverted joins. For example, an inverted join is
now generated for the following query:

    CREATE TABLE a (a INT, j JSON)
    CREATE TABLE b (b INT, j JSON, INVERTED INDEX (b, j))

    SELECT * FROM a JOIN b ON b = a AND b.j @> a.j

Previously, only constant filters could constrain non-inverted prefix
columns.

Release note: None

Co-authored-by: Marcus Gartner <[email protected]>
@craig
Copy link
Contributor

craig bot commented Dec 30, 2020

Build failed:

Non-inverted prefix columns can now be constrained by equality
constraints to generate inverted joins. For example, an inverted join is
now generated for the following query:

    CREATE TABLE a (a INT, j JSON)
    CREATE TABLE b (b INT, j JSON, INVERTED INDEX (b, j))

    SELECT * FROM a JOIN b ON b = a AND b.j @> a.j

Previously, only constant filters could constrain non-inverted prefix
columns.

Release note: None
@mgartner mgartner force-pushed the inverted-join-equality-cols branch from 48cc523 to b0db256 Compare December 30, 2020 17:17
@mgartner
Copy link
Collaborator Author

bors r+

@craig
Copy link
Contributor

craig bot commented Dec 30, 2020

Build succeeded:

@craig craig bot merged commit f23df8a into cockroachdb:master Dec 30, 2020
@mgartner mgartner deleted the inverted-join-equality-cols branch December 30, 2020 19:49
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.

4 participants