Changeset: 17815f9984ca for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=17815f9984ca
Modified Files:
sql/backends/monet5/sql.c
sql/backends/monet5/sql.mal
sql/backends/monet5/sql_scenario.c
sql/scripts/75_storagemodel.sql
Branch: mosaic
Log Message:
Extend storage() with update mode and compression
diffs (201 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
@@ -4400,13 +4400,13 @@ SQLoptimizersUpdate(Client cntxt, MalBlk
* Inspection of the actual storage footprint is a recurring question of users.
* This is modelled as a generic SQL table producing function.
* create function storage()
- * returns table ("schema" string, "table" string, "column" string, "type"
string, location string, "count" bigint, width int, columnsize bigint, heapsize
bigint indices bigint, sorted int)
+ * returns table ("schema" string, "table" string, "column" string, "type"
string, "mode" string, location string, "count" bigint, width int, columnsize
bigint, heapsize bigint indices bigint, sorted bit, compress bit)
* external name sql.storage;
*/
str
sql_storage(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
- BAT *sch, *tab, *col, *type, *loc, *cnt, *atom, *size, *heap, *indices,
*sort, *imprints;
+ BAT *sch, *tab, *col, *type, *loc, *cnt, *atom, *size, *heap, *indices,
*sort, *imprints, *mode, *compress;
mvc *m = NULL;
str msg;
sql_trans *tr;
@@ -4416,14 +4416,16 @@ sql_storage(Client cntxt, MalBlkPtr mb,
int *rtab = (int *) getArgReference(stk, pci, 1);
int *rcol = (int *) getArgReference(stk, pci, 2);
int *rtype = (int *) getArgReference(stk, pci, 3);
- int *rloc = (int *) getArgReference(stk, pci, 4);
- int *rcnt = (int *) getArgReference(stk, pci, 5);
- int *ratom = (int *) getArgReference(stk, pci, 6);
- int *rsize = (int *) getArgReference(stk, pci, 7);
- int *rheap = (int *) getArgReference(stk, pci, 8);
- int *rindices = (int *) getArgReference(stk, pci, 9);
- int *rimprints = (int *) getArgReference(stk, pci, 10);
- int *rsort = (int *) getArgReference(stk, pci, 11);
+ int *rmode = (int *) getArgReference(stk, pci, 4);
+ int *rloc = (int *) getArgReference(stk, pci, 5);
+ int *rcnt = (int *) getArgReference(stk, pci, 6);
+ int *ratom = (int *) getArgReference(stk, pci, 7);
+ int *rsize = (int *) getArgReference(stk, pci, 8);
+ int *rheap = (int *) getArgReference(stk, pci, 9);
+ int *rindices = (int *) getArgReference(stk, pci, 10);
+ int *rimprints = (int *) getArgReference(stk, pci, 11);
+ int *rsort = (int *) getArgReference(stk, pci, 12);
+ int *rcompress = (int *) getArgReference(stk, pci, 13);
if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL)
return msg;
@@ -4439,6 +4441,8 @@ sql_storage(Client cntxt, MalBlkPtr mb,
BATseqbase(col, 0);
type = BATnew(TYPE_void, TYPE_str, 0, TRANSIENT);
BATseqbase(type, 0);
+ mode = BATnew(TYPE_void, TYPE_str, 0, TRANSIENT);
+ BATseqbase(mode, 0);
loc = BATnew(TYPE_void, TYPE_str, 0, TRANSIENT);
BATseqbase(loc, 0);
cnt = BATnew(TYPE_void, TYPE_lng, 0, TRANSIENT);
@@ -4455,13 +4459,18 @@ sql_storage(Client cntxt, MalBlkPtr mb,
BATseqbase(imprints, 0);
sort = BATnew(TYPE_void, TYPE_bit, 0, TRANSIENT);
BATseqbase(sort, 0);
- if (sch == NULL || tab == NULL || col == NULL || type == NULL || loc ==
NULL || imprints == NULL || sort == NULL || cnt == NULL || atom == NULL || size
== NULL || heap == NULL || indices == NULL) {
+ compress = BATnew(TYPE_void, TYPE_bit, 0, TRANSIENT);
+ BATseqbase(compress, 0);
+ if (sch == NULL || tab == NULL || col == NULL || type == NULL || mode
== NULL || loc == NULL || imprints == NULL ||
+ sort == NULL || cnt == NULL || atom == NULL || size == NULL ||
heap == NULL || indices == NULL || compress == NULL) {
if (sch)
BBPreleaseref(sch->batCacheid);
if (tab)
BBPreleaseref(tab->batCacheid);
if (col)
BBPreleaseref(col->batCacheid);
+ if (mode)
+ BBPreleaseref(mode->batCacheid);
if (loc)
BBPreleaseref(loc->batCacheid);
if (cnt)
@@ -4480,6 +4489,8 @@ sql_storage(Client cntxt, MalBlkPtr mb,
BBPreleaseref(imprints->batCacheid);
if (sort)
BBPreleaseref(sort->batCacheid);
+ if (compress)
+ BBPreleaseref(compress->batCacheid);
throw(SQL, "sql.storage", MAL_MALLOC_FAIL);
}
for (nsch = tr->schemas.set->h; nsch; nsch = nsch->next) {
@@ -4503,6 +4514,16 @@ sql_storage(Client cntxt, MalBlkPtr mb,
sch =
BUNappend(sch, b->name, FALSE);
tab =
BUNappend(tab, bt->name, FALSE);
col =
BUNappend(col, bc->name, FALSE);
+ if
(c->t->access == TABLE_WRITABLE)
+ mode =
BUNappend(mode, "writable", FALSE);
+ else
+ if
(c->t->access == TABLE_APPENDONLY)
+ mode =
BUNappend(mode, "appendonly", FALSE);
+ else
+ if
(c->t->access == TABLE_READONLY)
+ mode =
BUNappend(mode, "readonly", FALSE);
+ else
+ mode =
BUNappend(mode, 0, FALSE);
type =
BUNappend(type, c->type.type->sqlname, FALSE);
/*printf(" cnt
"BUNFMT, BATcount(bn)); */
@@ -4552,6 +4573,9 @@ sql_storage(Client cntxt, MalBlkPtr mb,
w =
BATtordered(bn);
sort =
BUNappend(sort, &w, FALSE);
+
+ w =
bn->T->heap.compressed;
+ compress =
BUNappend(compress, &w, FALSE);
BBPunfix(bn->batCacheid);
}
@@ -4568,6 +4592,16 @@ sql_storage(Client cntxt, MalBlkPtr mb,
sch =
BUNappend(sch, b->name, FALSE);
tab =
BUNappend(tab, bt->name, FALSE);
col =
BUNappend(col, bc->name, FALSE);
+ if
(c->t->access == TABLE_WRITABLE)
+
mode = BUNappend(mode, "writable", FALSE);
+ else
+ if
(c->t->access == TABLE_APPENDONLY)
+
mode = BUNappend(mode, "appendonly", FALSE);
+ else
+ if
(c->t->access == TABLE_READONLY)
+
mode = BUNappend(mode, "readonly", FALSE);
+ else
+
mode = BUNappend(mode, 0, FALSE);
type =
BUNappend(type, "oid", FALSE);
/*printf(" cnt "BUNFMT, BATcount(bn)); */
@@ -4616,6 +4650,9 @@ sql_storage(Client cntxt, MalBlkPtr mb,
/*printf("\n"); */
w =
BATtordered(bn);
sort =
BUNappend(sort, &w, FALSE);
+
+ w =
bn->T->heap.compressed;
+
compress = BUNappend(compress, &w, FALSE);
BBPunfix(bn->batCacheid);
}
}
@@ -4626,6 +4663,7 @@ sql_storage(Client cntxt, MalBlkPtr mb,
BBPkeepref(*rsch = sch->batCacheid);
BBPkeepref(*rtab = tab->batCacheid);
BBPkeepref(*rcol = col->batCacheid);
+ BBPkeepref(*rmode = mode->batCacheid);
BBPkeepref(*rloc = loc->batCacheid);
BBPkeepref(*rtype = type->batCacheid);
BBPkeepref(*rcnt = cnt->batCacheid);
@@ -4635,6 +4673,7 @@ sql_storage(Client cntxt, MalBlkPtr mb,
BBPkeepref(*rindices = indices->batCacheid);
BBPkeepref(*rimprints = imprints->batCacheid);
BBPkeepref(*rsort = sort->batCacheid);
+ BBPkeepref(*rcompress = compress->batCacheid);
return MAL_SUCCEED;
}
diff --git a/sql/backends/monet5/sql.mal b/sql/backends/monet5/sql.mal
--- a/sql/backends/monet5/sql.mal
+++ b/sql/backends/monet5/sql.mal
@@ -464,6 +464,7 @@ pattern storage()(
table:bat[:oid,:str],
column:bat[:oid,:str],
type:bat[:oid,:str],
+ mode:bat[:oid,:str],
location:bat[:oid,:str],
count:bat[:oid,:lng],
atomwidth:bat[:oid,:int],
@@ -471,7 +472,8 @@ pattern storage()(
heap:bat[:oid,:lng],
hashes:bat[:oid,:lng],
imprints:bat[:oid,:lng],
- sorted:bat[:oid,:bit])
+ sorted:bat[:oid,:bit],
+ compress:bat[:oid,:bit])
address sql_storage
comment "return a table with storage information ";
diff --git a/sql/backends/monet5/sql_scenario.c
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -1087,6 +1087,12 @@ create aggregate json.tojsonarray( x dou
"insert into sys.systemfunctions (select f.id from
sys.functions f, sys.schemas s where f.name in ('bbp', 'db_users', 'env',
'generate_series', 'storage', 'storagemodel', 'var') and f.type = %d and
f.schema_id = s.id and s.name = 'sys');\n",
F_UNION);
+ /* new file 75_storagemodel.sql */
+ pos += snprintf(buf+pos, bufsize - pos, "drop function sys.storage;\n"
+ "create function sys.\"storage\"()\n"
+ "returns table (\"schema\" string, \"table\" string, \"column\" string,
\"type\" string, \"mode\" string,"
+ "location string, \"count\" bigint, typewidth int, columnsize bigint,
heapsize bigint, hashes bigint, imprints bigint, sorted boolean, compress
boolean)\n"
+ "external name sql.\"storage\";returns table (value tinyint)\n");
if (schema) {
pos += snprintf(buf + pos, bufsize - pos, "set schema
\"%s\";\n", schema);
free(schema);
diff --git a/sql/scripts/75_storagemodel.sql b/sql/scripts/75_storagemodel.sql
--- a/sql/scripts/75_storagemodel.sql
+++ b/sql/scripts/75_storagemodel.sql
@@ -29,7 +29,7 @@
-- For strings we take a sample to determine their average length.
create function sys."storage"()
-returns table ("schema" string, "table" string, "column" string, "type"
string, location string, "count" bigint, typewidth int, columnsize bigint,
heapsize bigint, hashes bigint, imprints bigint, sorted boolean)
+returns table ("schema" string, "table" string, "column" string, "type"
string, "mode" string, location string, "count" bigint, typewidth int,
columnsize bigint, heapsize bigint, hashes bigint, imprints bigint, sorted
boolean, compress boolean)
external name sql."storage";
create view sys."storage" as select * from sys."storage"();
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list