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

Missing SELECT results when filtering conditional on IS NULL on an indexed column along with any other condition #387

Open
davidfiala opened this issue Mar 13, 2024 · 1 comment

Comments

@davidfiala
Copy link

Describe the bug

In queries/updates on rows where you conditionally select on a column with an index against NULL /plus/ one more condition, the results will be empty.

Conditions required for bug:

  • WHERE clause with at least 2 conditions AND'd together
  • You must be checking for IS NULL or IS NOT NULL on an indexed column.
  • The indexed condition must come before some other unrelated condition.
    • The unrelated check can be as simple as true or 1=1, but it must be present.
    • The order is critical to reproduce this bug, as shown in the example below we demonstrate it only happens in one direction.

To Reproduce

https://oguimbal.github.io/pg-mem-playground/

CREATE TABLE "public"."foo" (apple integer,banana integer,charlie integer);
CREATE INDEX "idx1" on "public"."foo" ("apple"); -- when this index is removed, all queries return results
INSERT INTO "foo" (apple, banana, charlie) values (10, 20, 30);
SELECT * FROM FOO;
SELECT * FROM FOO WHERE TRUE;
SELECT * FROM FOO WHERE TRUE AND TRUE;
SELECT * FROM FOO WHERE APPLE = 10 AND TRUE;
SELECT * FROM FOO WHERE APPLE IS NOT NULL;
SELECT * FROM FOO WHERE TRUE AND APPLE IS NOT NULL;
SELECT * FROM FOO WHERE APPLE IS NOT NULL AND TRUE; -- **bug** Actual is empty, but expected results

-- just to prove it's both 'IS NULL' and 'IS NOT NULL' we flip it around too:
UPDATE FOO SET APPLE = NULL;
SELECT * FROM FOO;
SELECT * FROM FOO WHERE TRUE;
SELECT * FROM FOO WHERE TRUE AND TRUE;
SELECT * FROM FOO WHERE APPLE IS NULL;
SELECT * FROM FOO WHERE TRUE AND APPLE IS NULL;
SELECT * FROM FOO WHERE APPLE IS NULL AND TRUE; -- **bug** Actual is empty, but expected results

NOTE: When you comment out the index, all queries work.

pg-mem version

2.8.1

@abdul-mattee-pikessoft
Copy link

Still facing this issue with 2.8.1.

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

No branches or pull requests

2 participants