Changeset: eb4b262fa52e for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/eb4b262fa52e Modified Files: sql/backends/monet5/sql.c sql/test/BugTracker-2016/Tests/storagemodel.test Branch: Jul2021 Log Message:
Don't load bats in sys.storage() if we can avoid it.
diffs (189 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
@@ -3850,7 +3850,7 @@ SQLoptimizersUpdate(Client cntxt, MalBlk
str
sql_storage(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
- BAT *sch, *tab, *col, *type, *loc, *cnt, *atom, *size, *heap, *indices,
*phash, *sort, *imprints, *mode, *revsort, *key, *oidx, *bn = NULL, *bs = NULL;
+ BAT *sch, *tab, *col, *type, *loc, *cnt, *atom, *size, *heap, *indices,
*phash, *sort, *imprints, *mode, *revsort, *key, *oidx, *bs = NULL;
mvc *m = NULL;
str msg = MAL_SUCCEED;
sql_trans *tr;
@@ -3950,9 +3950,8 @@ sql_storage(Client cntxt, MalBlkPtr mb,
if( cname &&
strcmp(bc->name, cname) )
continue;
- bn =
store->storage_api.bind_col(tr, c, RDONLY); /* is slice */
bs =
store->storage_api.bind_col(tr, c, QUICK);
- if (bn == NULL || bs ==
NULL) {
+ if (bs == NULL) {
msg =
createException(SQL, "sql.storage", SQLSTATE(HY005) "Cannot access column
descriptor");
goto bailout;
}
@@ -3986,14 +3985,22 @@ sql_storage(Client cntxt, MalBlkPtr mb,
/*printf(" loc %s",
BBP_physical(bs->batCacheid)); */
if (BUNappend(loc,
BBP_physical(bs->batCacheid), false) != GDK_SUCCEED)
goto bailout;
- /*printf(" width %d",
bn->twidth); */
- w = bn->twidth;
- if (bn->ttype ==
TYPE_str) {
+ /*printf(" width %d",
bs->twidth); */
+ w = bs->twidth;
+ if (bs->ttype ==
TYPE_str) {
double sum = 0;
- BATiter bi =
bat_iterator(bn);
- lng cnt1, cnt2
= cnt1 = (lng) BATcount(bn);
- BAT *cands =
store->storage_api.bind_cands(tr, t, 1, 0);
- oid hseq =
bn->hseqbase;
+ BATiter bi;
+ lng cnt1, cnt2;
+ BAT *cands;
+ oid hseq;
+
+ BAT *bn =
store->storage_api.bind_col(tr, c, RDONLY); /* is slice */
+ if (bn == NULL)
+ goto
bailout;
+ bi =
bat_iterator(bn);
+ cnt2 = cnt1 =
(lng) BATcount(bn);
+ cands =
store->storage_api.bind_cands(tr, t, 1, 0);
+ hseq =
bn->hseqbase;
if (cands) {
BUN lo,
hi;
@@ -4013,19 +4020,21 @@ sql_storage(Client cntxt, MalBlkPtr mb,
BBPunfix(cands->batCacheid);
}
bat_iterator_end(&bi);
+
BBPunfix(bn->batCacheid);
+ bn = NULL;
if (cnt2)
w =
(int) (sum / cnt2);
- } else if
(ATOMvarsized(bn->ttype)) {
- sz =
BATcount(bn);
- if (sz > 0)
- w =
(int) ((bn->tvheap->free + sz / 2) / sz);
+ } else if
(ATOMvarsized(bs->ttype)) {
+ sz =
BATcount(bs);
+ if (sz > 0 &&
bs->tvheap)
+ w =
(int) ((bs->tvheap->free + sz / 2) / sz);
else
w = 0;
}
if (BUNappend(atom, &w,
false) != GDK_SUCCEED)
goto bailout;
- sz = BATcount(bs) <<
bn->tshift;
+ sz = BATcount(bs) <<
bs->tshift;
if (BUNappend(size,
&sz, false) != GDK_SUCCEED)
goto bailout;
@@ -4046,7 +4055,7 @@ sql_storage(Client cntxt, MalBlkPtr mb,
sz =
IMPSimprintsize(bs);
if (BUNappend(imprints,
&sz, false) != GDK_SUCCEED)
goto bailout;
- /*printf(" indices
"BUNFMT, bn->thash?bn->thash->heap.size:0); */
+ /*printf(" indices
"BUNFMT, bs->thash?bs->thash->heap.size:0); */
/*printf("\n"); */
bitval =
BATtordered(bs);
if (!bitval &&
bs->tnosorted == 0)
@@ -4069,8 +4078,6 @@ sql_storage(Client cntxt, MalBlkPtr mb,
sz = bs->torderidx &&
bs->torderidx != (Heap *) 1 ? bs->torderidx->free : 0;
if (BUNappend(oidx,
&sz, false) != GDK_SUCCEED)
goto bailout;
-
BBPunfix(bn->batCacheid);
- bn = NULL;
}
}
@@ -4079,11 +4086,10 @@ sql_storage(Client cntxt, MalBlkPtr mb,
sql_base *bc =
ncol->data;
sql_idx *c = (sql_idx
*) ncol->data;
if
(idx_has_column(c->type)) {
- bn =
store->storage_api.bind_idx(tr, c, RDONLY);
bs =
store->storage_api.bind_idx(tr, c, QUICK);
lng sz;
- if (bn == NULL
|| bs == NULL) {
+ if (bs == NULL)
{
msg =
createException(SQL, "sql.storage", SQLSTATE(HY005) "Cannot access column
descriptor");
goto
bailout;
}
@@ -4118,13 +4124,18 @@ sql_storage(Client cntxt, MalBlkPtr mb,
/*printf(" loc
%s", BBP_physical(bs->batCacheid)); */
if
(BUNappend(loc, BBP_physical(bs->batCacheid), false) != GDK_SUCCEED)
goto
bailout;
- /*printf("
width %d", bn->twidth); */
- w = bn->twidth;
- if (bn->ttype
== TYPE_str) {
+ /*printf("
width %d", bs->twidth); */
+ w = bs->twidth;
+ if (bs->ttype
== TYPE_str) {
BUN p,
q;
double
sum = 0;
- BATiter
bi = bat_iterator(bn);
- lng
cnt1, cnt2 = cnt1 = BATcount(bn);
+ BATiter
bi;
+ lng
cnt1, cnt2;
+ BAT *bn
= store->storage_api.bind_idx(tr, c, RDONLY);
+ if (bn
== NULL)
+
goto bailout;
+ bi =
bat_iterator(bn);
+ cnt2 =
cnt1 = BATcount(bn);
/* just
take a sample */
if
(cnt1 > 512)
@@ -4137,12 +4148,13 @@ sql_storage(Client cntxt, MalBlkPtr mb,
break;
}
bat_iterator_end(&bi);
+
BBPunfix(bn->batCacheid);
if
(cnt2)
w = (int) (sum / cnt2);
}
if
(BUNappend(atom, &w, false) != GDK_SUCCEED)
goto
bailout;
- /*printf(" size
"BUNFMT, tailsize(bn,BATcount(bn)) + (bn->tvheap? bn->tvheap->size:0)); */
+ /*printf(" size
"BUNFMT, tailsize(bs,BATcount(bs)) + (bs->tvheap? bs->tvheap->size:0)); */
sz =
tailsize(bs, BATcount(bs));
if
(BUNappend(size, &sz, false) != GDK_SUCCEED)
goto
bailout;
@@ -4183,8 +4195,6 @@ sql_storage(Client cntxt, MalBlkPtr mb,
sz =
bs->torderidx && bs->torderidx != (Heap *) 1 ? bs->torderidx->free : 0;
if
(BUNappend(oidx, &sz, false) != GDK_SUCCEED)
goto
bailout;
-
BBPunfix(bn->batCacheid);
- bn = NULL;
}
}
}
@@ -4213,8 +4223,6 @@ sql_storage(Client cntxt, MalBlkPtr mb,
return MAL_SUCCEED;
bailout:
- if (bn)
- BBPunfix(bn->batCacheid);
if (sch)
BBPunfix(sch->batCacheid);
if (tab)
diff --git a/sql/test/BugTracker-2016/Tests/storagemodel.test
b/sql/test/BugTracker-2016/Tests/storagemodel.test
--- a/sql/test/BugTracker-2016/Tests/storagemodel.test
+++ b/sql/test/BugTracker-2016/Tests/storagemodel.test
@@ -92,7 +92,7 @@ 0
2000
0
1
-1
+NULL
1
statement ok
@@ -198,7 +198,7 @@ 0
2000
0
1
-1
+NULL
1
statement ok
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list
