Changeset: 1296784f3fb0 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/1296784f3fb0
Modified Files:
sql/backends/monet5/dict.c
sql/test/dict/Tests/dict04.test
Branch: default
Log Message:
Another missing corner case. Look for NULL value input for thetaselect
diffs (169 lines):
diff --git a/sql/backends/monet5/dict.c b/sql/backends/monet5/dict.c
--- a/sql/backends/monet5/dict.c
+++ b/sql/backends/monet5/dict.c
@@ -717,48 +717,20 @@ DICTthetaselect(Client cntxt, MalBlkPtr
BUN p = BUN_NONE;
if (ATOMextern(lvi.type))
v = *(ptr*)v;
- if (op[0] == '=' || op[0] == '!') {
- p = BUNfnd(lv, v);
- } else if (op[0] == '<' || op[0] == '>') {
- p = SORTfndfirst(lv, v);
- if (p != BUN_NONE && op[0] == '<' && op[1] == '=') {
- if (ATOMcmp(lvi.type, v, BUNtail(lvi, p)) != 0)
- p--;
- }
- }
- if (p != BUN_NONE) {
- if (loi.type == TYPE_bte) {
- bte val = (bte)p;
- bn = BATthetaselect(lo, lc, &val, op);
- } else if (loi.type == TYPE_sht) {
- sht val = (sht)p;
- bn = BATthetaselect(lo, lc, &val, op);
- } else
- assert(0);
- if (bn && (op[0] == '<' || op[0] == '>' || op[0] ==
'!') && (!lvi.nonil || lvi.nil)) { /* filter the NULL value out */
- p = BUNfnd(lv, ATOMnilptr(lvi.type));
- if (p != BUN_NONE) {
- BAT *nbn = NULL;
- if (loi.type == TYPE_bte) {
- bte val = (bte)p;
- nbn = BATthetaselect(lo, bn,
&val, "<>");
- } else if (loi.type == TYPE_sht) {
- sht val = (sht)p;
- nbn = BATthetaselect(lo, bn,
&val, "<>");
- } else
- assert(0);
- BBPreclaim(bn);
- bn = nbn;
+ if (ATOMcmp(lvi.type, v, ATOMnilptr(lvi.type)) == 0) {
+ /* corner case, if v is NULL skip any calculations */
+ bn = BATdense(0, 0, 0);
+ } else {
+ if (op[0] == '=' || op[0] == '!') {
+ p = BUNfnd(lv, v);
+ } else if (op[0] == '<' || op[0] == '>') {
+ p = SORTfndfirst(lv, v);
+ if (p != BUN_NONE && op[0] == '<' && op[1] ==
'=') {
+ if (ATOMcmp(lvi.type, v, BUNtail(lvi,
p)) != 0)
+ p--;
}
}
- } else if (op[0] == '!') {
- if (!lvi.nonil || lvi.nil) { /* find a possible NULL
value */
- p = BUNfnd(lv, ATOMnilptr(lvi.type));
- } else {
- p = BUN_NONE;
- }
-
- if (p != BUN_NONE) { /* filter the NULL value out */
+ if (p != BUN_NONE) {
if (loi.type == TYPE_bte) {
bte val = (bte)p;
bn = BATthetaselect(lo, lc, &val, op);
@@ -767,14 +739,47 @@ DICTthetaselect(Client cntxt, MalBlkPtr
bn = BATthetaselect(lo, lc, &val, op);
} else
assert(0);
- } else if (lc) { /* all rows pass, use input candidate
list */
- bn = lc;
- BBPfix(lc->batCacheid); /* give one extra
physical reference to keep the count in the end */
- } else { /* otherwise return all rows */
- bn = BATdense(0, 0, BATcount(lo));
+ if (bn && (op[0] == '<' || op[0] == '>' ||
op[0] == '!') && (!lvi.nonil || lvi.nil)) { /* filter the NULL value out */
+ p = BUNfnd(lv, ATOMnilptr(lvi.type));
+ if (p != BUN_NONE) {
+ BAT *nbn = NULL;
+ if (loi.type == TYPE_bte) {
+ bte val = (bte)p;
+ nbn =
BATthetaselect(lo, bn, &val, "<>");
+ } else if (loi.type ==
TYPE_sht) {
+ sht val = (sht)p;
+ nbn =
BATthetaselect(lo, bn, &val, "<>");
+ } else
+ assert(0);
+ BBPreclaim(bn);
+ bn = nbn;
+ }
+ }
+ } else if (op[0] == '!') {
+ if (!lvi.nonil || lvi.nil) { /* find a possible
NULL value */
+ p = BUNfnd(lv, ATOMnilptr(lvi.type));
+ } else {
+ p = BUN_NONE;
+ }
+
+ if (p != BUN_NONE) { /* filter the NULL value
out */
+ if (loi.type == TYPE_bte) {
+ bte val = (bte)p;
+ bn = BATthetaselect(lo, lc,
&val, op);
+ } else if (loi.type == TYPE_sht) {
+ sht val = (sht)p;
+ bn = BATthetaselect(lo, lc,
&val, op);
+ } else
+ assert(0);
+ } else if (lc) { /* all rows pass, use input
candidate list */
+ bn = lc;
+ BBPfix(lc->batCacheid); /* give one
extra physical reference to keep the count in the end */
+ } else { /* otherwise return all rows */
+ bn = BATdense(0, 0, BATcount(lo));
+ }
+ } else {
+ bn = BATdense(0, 0, 0);
}
- } else {
- bn = BATdense(0, 0, 0);
}
} else { /* select + intersect */
if (ATOMextern(lvi.type))
diff --git a/sql/test/dict/Tests/dict04.test b/sql/test/dict/Tests/dict04.test
--- a/sql/test/dict/Tests/dict04.test
+++ b/sql/test/dict/Tests/dict04.test
@@ -261,10 +261,10 @@ statement ok
START TRANSACTION
statement ok
-CREATE TABLE t0 (c0 INT)
+CREATE TABLE t0 (c0 INT, c1 DOUBLE PRECISION)
statement ok rowcount 1
-INSERT INTO t0 VALUES (NULL)
+INSERT INTO t0 VALUES (NULL, 0.1338142586871145)
statement ok
COMMIT
@@ -272,6 +272,9 @@ COMMIT
statement ok
CALL "sys"."dict_compress"('sys','t0','c0', true)
+statement ok
+CALL "sys"."dict_compress"('sys','t0','c1', true)
+
query I nosort
SELECT 1 FROM t0 WHERE t0.c0 < 1
----
@@ -296,13 +299,22 @@ query I nosort
SELECT 1 FROM t0 WHERE t0.c0 <> 1
----
+# output of json."integer"(JSON '{"x":"x"}') is NULL
+query I nosort
+SELECT 1 FROM t0 WHERE t0.c1 >= json."integer"(JSON '{"x":"x"}')
+----
+
statement ok rowcount 1
-INSERT INTO t0 VALUES (1)
+INSERT INTO t0 VALUES (1, NULL)
query I nosort
SELECT t0.c0 FROM t0 WHERE t0.c0 <> 1
----
+query I nosort
+SELECT 1 FROM t0 WHERE t0.c1 >= json."integer"(JSON '{"x":"x"}')
+----
+
statement ok
DROP TABLE t0
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]