Skip to content

opt: constrain multi-col inverted index prefix cols by contiguous range#56835

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
mgartner:contiguous-range
Nov 20, 2020
Merged

opt: constrain multi-col inverted index prefix cols by contiguous range#56835
craig[bot] merged 1 commit intocockroachdb:masterfrom
mgartner:contiguous-range

Conversation

@mgartner
Copy link
Copy Markdown
Contributor

This commit allows for the prefix columns of multi-column inverted
indexes to be constrained to a contiguous range. For example, consider
the schema and query:

CREATE TABLE t (
    k INT PRIMARY KEY,
    i INT,
    g GEOMETRY,
    INVERTED INDEX (i, g)
)

SELECT k FROM t WHERE i IN (1, 2, 3) AND ST_CoveredBy(..., g)

Prior to this commit, a scan over the inverted index would not be
generated for this query.

Release note: None

@mgartner mgartner requested a review from a team as a code owner November 18, 2020 01:01
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
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 (waiting on @RaduBerinde and @rytaft)

Copy link
Copy Markdown
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 3 of 3 files at r1.
Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @mgartner)


pkg/sql/opt/invertedidx/inverted_index_expr.go, line 303 at r1 (raw file):

		// length. Therefore, if the Prefix of the consolidated constraint is
		// less than the number of prefix columns, we try the unconsolidated
		// constraint. This allows us the optimizer to plan multi-column

[nit] us the optimizer -> the optimizer (or us! just pick one 🙂 )


pkg/sql/opt/invertedidx/inverted_index_expr.go, line 318 at r1 (raw file):

		constraint = ic.UnconsolidatedConstraint()
		if constraint.Prefix(evalCtx) < prefixColumnCount {
			// If the all of the unconsolidated constraint spans do not have the

[nit] the all -> all

@mgartner
Copy link
Copy Markdown
Contributor Author

mgartner commented Nov 18, 2020

Thinking about this some more, I don't think we'd ever want to use a consolidate constraint in this instance. Any constraint that can be consolidated would be consolidated into one or more spans that doesn't have the same start and end key. So I think we only need to check the unconsolidated constraint here. Does anyone see a problem with that?

Copy link
Copy Markdown
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.

So I think we only need to check the unconsolidated constraint here. Does anyone see a problem with that?

Makes sense to me

Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @mgartner)

Copy link
Copy Markdown
Contributor 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.

Makes sense to me

Cool. PTAL!

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


pkg/sql/opt/invertedidx/inverted_index_expr.go, line 303 at r1 (raw file):

Previously, rytaft (Rebecca Taft) wrote…

[nit] us the optimizer -> the optimizer (or us! just pick one 🙂 )

Done.


pkg/sql/opt/invertedidx/inverted_index_expr.go, line 318 at r1 (raw file):

Previously, rytaft (Rebecca Taft) wrote…

[nit] the all -> all

Done.

Copy link
Copy Markdown
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 5 of 5 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale)

This commit allows for the prefix columns of multi-column inverted
indexes to be constrained to a contiguous range. For example, consider
the schema and query:

    CREATE TABLE t (
        k INT PRIMARY KEY,
        i INT,
        g GEOMETRY,
        INVERTED INDEX (i, g)
    )

    SELECT k FROM t WHERE i IN (1, 2, 3) AND ST_CoveredBy(..., g)

Prior to this commit, a scan over the inverted index would not be
generated for this query.

Release note: None
@mgartner
Copy link
Copy Markdown
Contributor Author

TFTRs!

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Nov 20, 2020

Build succeeded:

@craig craig bot merged commit 06cb7c1 into cockroachdb:master Nov 20, 2020
@mgartner mgartner deleted the contiguous-range branch November 20, 2020 01:28
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