Changeset: 7ee2bb86a943 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/7ee2bb86a943
Modified Files:
sql/backends/monet5/sql.c
sql/test/BugTracker-2022/Tests/All
sql/test/BugTracker-2022/Tests/index-function-query.Bug-7238.test
Branch: Jan2022
Log Message:
You cannot create an integer view on an string offset bat.
This fixes bug #7238.
diffs (269 lines):
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -4191,43 +4191,33 @@ BATSTRindex_int(bat *res, const bat *src
if ((s = BATdescriptor(*src)) == NULL)
throw(SQL, "calc.index", SQLSTATE(HY005) "Cannot access column
descriptor");
- if (*u) {
- Heap *h = s->tvheap;
- size_t pad, pos;
- int v;
-
- r = COLnew(0, TYPE_int, 1024, TRANSIENT);
- if (r == NULL) {
+ (void) u;
+
+ Heap *h = s->tvheap;
+ size_t pad, pos;
+ int v;
+
+ r = COLnew(0, TYPE_int, 1024, TRANSIENT);
+ if (r == NULL) {
+ BBPunfix(s->batCacheid);
+ throw(SQL, "calc.index", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ }
+ pos = GDK_STRHASHSIZE;
+ while (pos < h->free) {
+ const char *p;
+
+ pad = GDK_VARALIGN - (pos & (GDK_VARALIGN - 1));
+ if (pad < sizeof(stridx_t))
+ pad += GDK_VARALIGN;
+ pos += pad;
+ p = h->base + pos;
+ v = (int) (pos - GDK_STRHASHSIZE);
+ if (BUNappend(r, &v, false) != GDK_SUCCEED) {
+ BBPreclaim(r);
BBPunfix(s->batCacheid);
throw(SQL, "calc.index", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
}
- pos = GDK_STRHASHSIZE;
- while (pos < h->free) {
- const char *p;
-
- pad = GDK_VARALIGN - (pos & (GDK_VARALIGN - 1));
- if (pad < sizeof(stridx_t))
- pad += GDK_VARALIGN;
- pos += pad;
- p = h->base + pos;
- v = (int) (pos - GDK_STRHASHSIZE);
- if (BUNappend(r, &v, false) != GDK_SUCCEED) {
- BBPreclaim(r);
- BBPunfix(s->batCacheid);
- throw(SQL, "calc.index", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
- }
- pos += strLen(p);
- }
- } else {
- r = VIEWcreate(s->hseqbase, s);
- if (r == NULL) {
- BBPunfix(s->batCacheid);
- throw(SQL, "calc.index", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
- }
- r->ttype = TYPE_int;
- r->tvarsized = false;
- HEAPdecref(r->tvheap, false);
- r->tvheap = NULL;
+ pos += strLen(p);
}
BBPunfix(s->batCacheid);
BBPkeepref((*res = r->batCacheid));
@@ -4250,42 +4240,32 @@ BATSTRindex_sht(bat *res, const bat *src
if ((s = BATdescriptor(*src)) == NULL)
throw(SQL, "calc.index", SQLSTATE(HY005) "Cannot access column
descriptor");
- if (*u) {
- Heap *h = s->tvheap;
- size_t pad, pos;
- sht v;
-
- r = COLnew(0, TYPE_sht, 1024, TRANSIENT);
- if (r == NULL) {
- BBPunfix(s->batCacheid);
+ (void) u;
+
+ Heap *h = s->tvheap;
+ size_t pad, pos;
+ sht v;
+
+ r = COLnew(0, TYPE_sht, 1024, TRANSIENT);
+ if (r == NULL) {
+ BBPunfix(s->batCacheid);
+ throw(SQL, "calc.index", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ }
+ pos = GDK_STRHASHSIZE;
+ while (pos < h->free) {
+ const char *s;
+
+ pad = GDK_VARALIGN - (pos & (GDK_VARALIGN - 1));
+ if (pad < sizeof(stridx_t))
+ pad += GDK_VARALIGN;
+ pos += pad;
+ s = h->base + pos;
+ v = (sht) (pos - GDK_STRHASHSIZE);
+ if (BUNappend(r, &v, false) != GDK_SUCCEED) {
+ BBPreclaim(r);
throw(SQL, "calc.index", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
}
- pos = GDK_STRHASHSIZE;
- while (pos < h->free) {
- const char *s;
-
- pad = GDK_VARALIGN - (pos & (GDK_VARALIGN - 1));
- if (pad < sizeof(stridx_t))
- pad += GDK_VARALIGN;
- pos += pad;
- s = h->base + pos;
- v = (sht) (pos - GDK_STRHASHSIZE);
- if (BUNappend(r, &v, false) != GDK_SUCCEED) {
- BBPreclaim(r);
- throw(SQL, "calc.index", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
- }
- pos += strLen(s);
- }
- } else {
- r = VIEWcreate(s->hseqbase, s);
- if (r == NULL) {
- BBPunfix(s->batCacheid);
- throw(SQL, "calc.index", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
- }
- r->ttype = TYPE_sht;
- r->tvarsized = false;
- HEAPdecref(r->tvheap, false);
- r->tvheap = NULL;
+ pos += strLen(s);
}
BBPunfix(s->batCacheid);
BBPkeepref((*res = r->batCacheid));
@@ -4308,43 +4288,33 @@ BATSTRindex_bte(bat *res, const bat *src
if ((s = BATdescriptor(*src)) == NULL)
throw(SQL, "calc.index", SQLSTATE(HY005) "Cannot access column
descriptor");
- if (*u) {
- Heap *h = s->tvheap;
- size_t pad, pos;
- bte v;
-
- r = COLnew(0, TYPE_bte, 64, TRANSIENT);
- if (r == NULL) {
+ (void) u;
+
+ Heap *h = s->tvheap;
+ size_t pad, pos;
+ bte v;
+
+ r = COLnew(0, TYPE_bte, 64, TRANSIENT);
+ if (r == NULL) {
+ BBPunfix(s->batCacheid);
+ throw(SQL, "calc.index", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ }
+ pos = GDK_STRHASHSIZE;
+ while (pos < h->free) {
+ const char *p;
+
+ pad = GDK_VARALIGN - (pos & (GDK_VARALIGN - 1));
+ if (pad < sizeof(stridx_t))
+ pad += GDK_VARALIGN;
+ pos += pad;
+ p = h->base + pos;
+ v = (bte) (pos - GDK_STRHASHSIZE);
+ if (BUNappend(r, &v, false) != GDK_SUCCEED) {
+ BBPreclaim(r);
BBPunfix(s->batCacheid);
throw(SQL, "calc.index", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
}
- pos = GDK_STRHASHSIZE;
- while (pos < h->free) {
- const char *p;
-
- pad = GDK_VARALIGN - (pos & (GDK_VARALIGN - 1));
- if (pad < sizeof(stridx_t))
- pad += GDK_VARALIGN;
- pos += pad;
- p = h->base + pos;
- v = (bte) (pos - GDK_STRHASHSIZE);
- if (BUNappend(r, &v, false) != GDK_SUCCEED) {
- BBPreclaim(r);
- BBPunfix(s->batCacheid);
- throw(SQL, "calc.index", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
- }
- pos += strLen(p);
- }
- } else {
- r = VIEWcreate(s->hseqbase, s);
- if (r == NULL) {
- BBPunfix(s->batCacheid);
- throw(SQL, "calc.index", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
- }
- r->ttype = TYPE_bte;
- r->tvarsized = false;
- HEAPdecref(r->tvheap, false);
- r->tvheap = NULL;
+ pos += strLen(p);
}
BBPunfix(s->batCacheid);
BBPkeepref((*res = r->batCacheid));
diff --git a/sql/test/BugTracker-2022/Tests/All
b/sql/test/BugTracker-2022/Tests/All
--- a/sql/test/BugTracker-2022/Tests/All
+++ b/sql/test/BugTracker-2022/Tests/All
@@ -1,3 +1,3 @@
transaction-conflict.Bug-7228
insert-not-null.Bug-7232
-index-function-query.Bug-7238
+!ARCH_BITS32?index-function-query.Bug-7238
diff --git a/sql/test/BugTracker-2022/Tests/index-function-query.Bug-7238.test
b/sql/test/BugTracker-2022/Tests/index-function-query.Bug-7238.test
--- a/sql/test/BugTracker-2022/Tests/index-function-query.Bug-7238.test
+++ b/sql/test/BugTracker-2022/Tests/index-function-query.Bug-7238.test
@@ -4,8 +4,8 @@ create table t7238 (name varchar(22) NOT
statement ok
INSERT INTO t7238 VALUES ('sys'),('tmp'),('json'),('profiler')
-query TI
-select name, length(name) as nm_len from t7238 order by nm_len;
+query TI nosort
+select name, length(name) as nm_len from t7238 order by nm_len
----
sys
3
@@ -16,30 +16,27 @@ 4
profiler
8
-query TI
+query TI nosort
select name, "index"(name, true) nm_idx from t7238 order by nm_idx
----
sys
-4
+8
tmp
-12
+24
json
-20
+40
profiler
-32
+56
-query TI
+query TI nosort
select name, "index"(name, false) nm_idx from t7238 order by nm_idx
----
sys
-4
+8
tmp
-12
+24
json
-20
+40
profiler
-32
+56
-statement ok
-drop table t7238
-
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list