sql: fix crash when using a partial index with predicate that has a UDF#171000
sql: fix crash when using a partial index with predicate that has a UDF#171000dils2k wants to merge 1 commit into
Conversation
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
|
It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR? Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
cd4ad88 to
d123a66
Compare
|
It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR? Thank you for updating your pull request. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
DrewKimball
left a comment
There was a problem hiding this comment.
This approach looks good to me. We'll need tests for both changes, though.
@DrewKimball reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status:complete! 0 of 0 LGTMs obtained (waiting on dils2k).
|
@DrewKimball Actually I was thinking about this approach and it turns out we will get an error every time a partial index predicate has a non-inlinable UDF. For example, if we use a bitwise "and" instead of a module operator, then we will get the same error: CREATE FUNCTION is_even(i INT) RETURNS BOOL AS $$
-- NOTE: bitwise operator, not module
SELECT i & 1 = 0;
$$ LANGUAGE SQL IMMUTABLE;
CREATE TABLE t (
k INT PRIMARY KEY,
a INT,
INDEX (a) WHERE is_even(k)
);
CREATE INDEX partial_idx ON t(a) where is_even(k);
-- ERROR: index "t_a_idx" is a partial index that does not contain all the rows needed to execute this query SQLSTATE:
-- 42809Should I also include bitwise operations in CREATE FUNCTION is_cat(s varchar) RETURNS BOOL AS $$
SELECT lower(s) = 'cat';
$$ LANGUAGE SQL IMMUTABLE;
CREATE TABLE tt ( a varchar );
CREATE INDEX partial_idx ON tt(a) WHERE is_cat(a);
-- ERROR: index "partial_idx" is a partial index that does not contain all the rows needed to execute this query
-- SQLSTATE: 42809 |
|
@dils2k I think we can safely add simple operators like bitwise AND to that list, maybe in separate commit or PR. You're right that in the general case, this isn't enough to prevent |
d123a66 to
775b0bc
Compare
|
Thank you for updating your pull request. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
d1e18cb to
088c7eb
Compare
Using a partial index with predicate that references a UDF produces a Project expression that was not handled during partial index contruction in the optimizer, causing an error. This commit fixes it by handling Project expressions and also inlining additional expressions. Epic: CRDB-55454 Release note: None Fixes: cockroachdb#155488
088c7eb to
4cdca27
Compare
|
@DrewKimball PTAL when you have time. There were places in the tests where division was (AFAIU) expected to be a non-inlinable operation, I replaced it with a bitwise AND in those cases. |
I receive this error: |
Using a partial index with predicate that references a UDF produces a Project expression that was not handled during partial index contruction in the optimizer, causing an error. This commit fixes it by handling Project expressions and also inlining additional expressions.
Epic: CRDB-55454
Release note: None
Fixes: #155488