Skip to content

Commit 9a89986

Browse files
andriizavoikooguimbal
authored andcommitted
fix indexed column eqfilter conditioning for is null operator
1 parent 8f84e85 commit 9a89986

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/tests/simple-queries.spec.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -502,5 +502,16 @@ describe('Simple queries', () => {
502502
members VARCHAR[]
503503
);`);
504504
expectQueryError(() => none(`INSERT INTO example (members) VALUES (ARRAY[])`), /cannot determine type of empty array/);
505-
})
505+
});
506+
507+
it('should select row with null value condition for indexed column', async () => {
508+
none(`
509+
CREATE TABLE "tableA" ("id" SERIAL NOT NULL, "reference" INTEGER);
510+
CREATE INDEX "IDX_1" ON "tableA" ("reference");
511+
INSERT INTO "tableA"(id, reference) values (1, null);
512+
`);
513+
// it is important that EqFilter hasItem gets called, so two same conditions are applied to fall both into best and sorted conditions
514+
const got = many(`SELECT "tableA"."id" FROM "tableA" WHERE ("tableA"."id" IN (1, 2) AND "tableA"."reference" IS NULL) AND ("tableA"."id" IN (1, 2) AND "tableA"."reference" IS NULL)`);
515+
expect(got).toHaveLength(1);
516+
});
506517
});

src/transforms/eq-filter.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,20 @@ export class EqFilter extends FilterBase {
2828
}
2929

3030
hasItem(item: Row, t: _Transaction) {
31+
const isEq = this.op === 'eq';
3132
const val = this.onValue.get(item, t);
33+
34+
if (this.matchNull && nullIsh(val)) {
35+
return isEq;
36+
}
3237
if (nullIsh(val)) {
3338
return false;
3439
}
3540
const eq = this.onValue.type.equals(val, this.equalsCst);
3641
if (nullIsh(eq)) {
3742
return false;
3843
}
39-
return this.op === 'eq' ? !!eq : !eq;
44+
return isEq ? !!eq : !eq;
4045
}
4146

4247
constructor(private onValue: IValue

0 commit comments

Comments
 (0)