Changeset: a2026d547201 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a2026d547201
Modified Files:
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql.mal
        sql/backends/monet5/sql_upgrades.c
        sql/scripts/75_storagemodel.sql
Branch: default
Log Message:

Introduce persistent hash enquiry
The storage() function should return if a hash is persistent
and if so also its size. These are the hooks for the GDK extension.


diffs (137 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
@@ -4288,12 +4288,13 @@ 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, 
*sort, *imprints, *mode;
+       BAT *sch, *tab, *col, *type, *loc, *cnt, *atom, *size, *heap, *indices, 
*phash, *sort, *imprints, *mode;
        mvc *m = NULL;
        str msg;
        sql_trans *tr;
        node *nsch, *ntab, *ncol;
        int w;
+       bit bitval;
        bat *rsch = getArgReference_bat(stk, pci, 0);
        bat *rtab = getArgReference_bat(stk, pci, 1);
        bat *rcol = getArgReference_bat(stk, pci, 2);
@@ -4305,8 +4306,9 @@ sql_storage(Client cntxt, MalBlkPtr mb, 
        bat *rsize = getArgReference_bat(stk, pci, 8);
        bat *rheap = getArgReference_bat(stk, pci, 9);
        bat *rindices = getArgReference_bat(stk, pci, 10);
-       bat *rimprints = getArgReference_bat(stk, pci, 11);
-       bat *rsort = getArgReference_bat(stk, pci, 12);
+       bat *rphash = getArgReference_bat(stk, pci, 11);
+       bat *rimprints = getArgReference_bat(stk, pci, 12);
+       bat *rsort = getArgReference_bat(stk, pci, 13);
 
        if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL)
                return msg;
@@ -4336,6 +4338,8 @@ sql_storage(Client cntxt, MalBlkPtr mb, 
        BATseqbase(heap, 0);
        indices = BATnew(TYPE_void, TYPE_lng, 0, TRANSIENT);
        BATseqbase(indices, 0);
+       phash = BATnew(TYPE_void, TYPE_bit, 0, TRANSIENT);
+       BATseqbase(phash, 0);
        imprints = BATnew(TYPE_void, TYPE_lng, 0, TRANSIENT);
        BATseqbase(imprints, 0);
        sort = BATnew(TYPE_void, TYPE_bit, 0, TRANSIENT);
@@ -4343,7 +4347,7 @@ sql_storage(Client cntxt, MalBlkPtr mb, 
        
 
        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) {
+               sort == NULL || cnt == NULL || atom == NULL || size == NULL || 
heap == NULL || indices == NULL || phash == NULL) {
                if (sch)
                        BBPunfix(sch->batCacheid);
                if (tab)
@@ -4366,6 +4370,8 @@ sql_storage(Client cntxt, MalBlkPtr mb, 
                        BBPunfix(heap->batCacheid);
                if (indices)
                        BBPunfix(indices->batCacheid);
+               if (phash)
+                       BBPunfix(phash->batCacheid);
                if (imprints)
                        BBPunfix(imprints->batCacheid);
                if (sort)
@@ -4442,9 +4448,12 @@ sql_storage(Client cntxt, MalBlkPtr mb, 
                                                                sz += 
bn->H->vheap ? bn->H->vheap->size : 0;
                                                                BUNappend(heap, 
&sz, FALSE);
 
-                                                               sz = 
bn->T->hash ? bn->T->hash->heap->size : 0;
-                                                               sz += 
bn->H->hash ? bn->H->hash->heap->size : 0;
+                                                               sz = 
bn->T->hash ? bn->T->hash->heap->size : 0; // HASHsize(bn)
+                                                               sz += 
bn->H->hash ? bn->H->hash->heap->size : 0; // HASHsize(bn)
                                                                
BUNappend(indices, &sz, FALSE);
+                                                               bitval = 0; // 
HASHispersistent(bn);
+                                                               
BUNappend(phash, &bitval, FALSE);
+
                                                                sz = 
IMPSimprintsize(bn);
                                                                
BUNappend(imprints, &sz, FALSE);
                                                                /*printf(" 
indices "BUNFMT, bn->T->hash?bn->T->hash->heap->size:0); */
@@ -4517,9 +4526,12 @@ sql_storage(Client cntxt, MalBlkPtr mb, 
                                                                        sz += 
bn->H->vheap ? bn->H->vheap->size : 0;
                                                                        
BUNappend(heap, &sz, FALSE);
 
-                                                                       sz = 
bn->T->hash ? bn->T->hash->heap->size : 0;
-                                                                       sz += 
bn->H->hash ? bn->H->hash->heap->size : 0;
+                                                                       sz = 
bn->T->hash ? bn->T->hash->heap->size : 0; // HASHsize()
+                                                                       sz += 
bn->H->hash ? bn->H->hash->heap->size : 0; // HASHsize()
                                                                        
BUNappend(indices, &sz, FALSE);
+                                                                       bitval 
= 0; // HASHispersistent(bn);
+                                                                       
BUNappend(phash, &bitval, FALSE);
+
                                                                        sz = 
IMPSimprintsize(bn);
                                                                        
BUNappend(imprints, &sz, FALSE);
                                                                        
/*printf(" indices "BUNFMT, bn->T->hash?bn->T->hash->heap->size:0); */
@@ -4544,6 +4556,7 @@ sql_storage(Client cntxt, MalBlkPtr mb, 
        BBPkeepref(*rsize = size->batCacheid);
        BBPkeepref(*rheap = heap->batCacheid);
        BBPkeepref(*rindices = indices->batCacheid);
+       BBPkeepref(*rphash = phash->batCacheid);
        BBPkeepref(*rimprints = imprints->batCacheid);
        BBPkeepref(*rsort = sort->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
@@ -462,6 +462,7 @@ pattern storage()(
        columnsize:bat[:oid,:lng],
        heap:bat[:oid,:lng],
        hashes:bat[:oid,:lng],
+       phash:bat[:oid,:bit],
        imprints:bat[:oid,:lng],
        sorted:bat[:oid,:bit])
 address sql_storage
diff --git a/sql/backends/monet5/sql_upgrades.c 
b/sql/backends/monet5/sql_upgrades.c
--- a/sql/backends/monet5/sql_upgrades.c
+++ b/sql/backends/monet5/sql_upgrades.c
@@ -1395,6 +1395,15 @@ where qd.id = ql.id and qd.owner = user;
        }
        assert(pos < bufsize);
 
+       /* update the 75_storagemodel script */
+       pos += snprintf(buf + pos, bufsize - pos, "drop function 
sys.storage();\n");
+       pos += snprintf(buf + pos, bufsize - pos, 
+               "create function sys.\"storage\"()"
+               "returns table (\"schema\" string, \"table\" string, \"column\" 
string, \"type\" string,"
+               "\"mode\" string, location string, \"count\" bigint, typewidth 
int, columnsize bigint, "
+               "heapsize bigint, hashes bigint, phash boolean, imprints 
bigint, sorted boolean)"
+               "external name sql.\"storage\";\n"
+       );
        printf("Running database upgrade commands:\n%s\n", buf);
        err = SQLstatementIntern(c, &buf, "update", 1, 0, NULL);
        GDKfree(buf);
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
@@ -18,7 +18,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, "mode" 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, phash boolean, imprints 
bigint, sorted boolean)
 external name sql."storage";
 
 create view sys."storage" as select * from sys."storage"();
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to