Changeset: 31170a1db336 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=31170a1db336
Modified Files:
        sql/src/backends/monet5/sql.mx
Branch: default
Log Message:

The storage inspection table
Users would like to have an easy way to assess the database storage footprint.


diffs (140 lines):

diff -r 70fab7f1e1f1 -r 31170a1db336 sql/src/backends/monet5/sql.mx
--- a/sql/src/backends/monet5/sql.mx    Thu Jan 13 15:41:02 2011 +0100
+++ b/sql/src/backends/monet5/sql.mx    Fri Jan 14 08:47:25 2011 +0100
@@ -480,6 +480,11 @@
 pattern dump_slave() :bat[:str,:bat]
 address dump_slave
 comment "Dump the status of the slave synchronization";
+
+pattern storage():bat[:str,:bat]
+address sql_storage
+comment "return a table with storage information ";
+
 @- SQL function aliases
 The code generate should identify the precise module
 target for all functions. This creates quite some
@@ -5596,3 +5601,124 @@
 #endif /* RDF */
 }
 
+@-
+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, location 
string, cnt bigint, cap bigint, width int, size bigint, auxsize bigint)
+external name sql.storage;
+@c
+str
+sql_storage(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+       int *res = (int*) getArgReference(stk,pci,0);
+       BAT *sch, *tab, *col, *loc, *cnt, *cap, *atom, *size, *aux, *r;
+       sql_schema      *s;
+       sql_table       *t;
+       sql_column      *c;
+       mvc *m = NULL;
+       str msg = getContext(cntxt,mb, &m, NULL);
+       sql_trans *tr = m->session->tr;
+       node *nsch, *ntab, *ncol;
+
+       if (msg)
+               return msg;
+       (void) s;
+       (void) t;
+       (void) c;
+
+       sch = BATnew(TYPE_void,TYPE_str, 0);
+       BATseqbase(sch, 0);
+       tab = BATnew(TYPE_void,TYPE_str, 0);
+       BATseqbase(tab, 0);
+       col = BATnew(TYPE_void,TYPE_str, 0);
+       BATseqbase(col, 0);
+       loc = BATnew(TYPE_void,TYPE_str, 0);
+       BATseqbase(loc, 0);
+       cnt = BATnew(TYPE_void,TYPE_lng, 0);
+       BATseqbase(cnt, 0);
+       cap = BATnew(TYPE_void,TYPE_lng, 0);
+       BATseqbase(cap, 0);
+       atom = BATnew(TYPE_void,TYPE_int, 0);
+       BATseqbase(atom, 0);
+       size = BATnew(TYPE_void,TYPE_lng, 0);
+       BATseqbase(size, 0);
+       aux = BATnew(TYPE_void,TYPE_lng, 0);
+       BATseqbase(aux, 0);
+       if ( sch == NULL || tab == NULL || col == NULL || loc == NULL ||
+                cnt == NULL || cap == NULL || atom == NULL || size == NULL || 
aux == NULL){
+               if ( sch ) BBPreleaseref(sch->batCacheid);
+               if ( tab ) BBPreleaseref(tab->batCacheid);
+               if ( col ) BBPreleaseref(col->batCacheid);
+               if ( loc ) BBPreleaseref(loc->batCacheid);
+               if ( cnt ) BBPreleaseref(cnt->batCacheid);
+               if ( cap ) BBPreleaseref(cap->batCacheid);
+               if ( atom ) BBPreleaseref(atom->batCacheid);
+               if ( size ) BBPreleaseref(size->batCacheid);
+               if ( aux ) BBPreleaseref(aux->batCacheid);
+               throw(SQL,"sql.storage", MAL_MALLOC_FAIL);
+       }
+       for( nsch= tr->schemas.set->h; nsch; nsch= nsch->next){
+               sql_base *b= nsch->data;
+               s= (sql_schema*) nsch->data;
+               if ( isalpha((int)b->name[0]) )
+               for(ntab= (s)->tables.set->h ;ntab; ntab= ntab->next){
+                       sql_base *bt= ntab->data;
+                       t= (sql_table*) bt;
+                       for (ncol= (t)->columns.set->h; ncol; ncol= ncol->next){
+                               sql_base *bc = ncol->data;
+                               sql_column *c= (sql_column *) ncol->data;
+                               BAT *bn = store_funcs.bind_col(tr, c, 0);
+                               BUN sz;
+
+                               printf("schema %s.%s.%s" , b->name, bt->name, 
bc->name);
+                               sch = BUNappend(sch, &b->name, FALSE);
+                               tab = BUNappend(tab, &bt->name, FALSE);
+                               col = BUNappend(col, &bc->name, FALSE);
+
+                               printf(" cnt "BUNFMT, BATcount(bn));
+                               sz= BATcount(bn);
+                               cnt = BUNappend(cnt, &sz, FALSE);
+                               printf(" cap "BUNFMT, BATcapacity(bn));
+                               sz= BATcapacity(bn);
+                               cap = BUNappend(cap, &sz, FALSE);
+
+                               printf(" loc %s", BBP_physical(bn->batCacheid));
+                               loc = BUNappend(loc, 
&BBP_physical(bn->batCacheid), FALSE);
+                               printf(" width %d", bn->T->width);
+                               atom = BUNappend(atom, &bn->T->width, FALSE);
+                               printf(" size "BUNFMT, 
tailsize(bn,BATcount(bn)) + (bn->T->vheap? bn->T->vheap->size:0));
+                               sz = tailsize(bn,BATcount(bn)) + (bn->T->vheap? 
bn->T->vheap->size:0);
+                               size = BUNappend(size, &sz, FALSE);
+                               
+                               sz =  bn->T->hash?bn->T->hash->heap->size:0;
+                               aux = BUNappend(aux, &sz, FALSE);
+                               printf(" auxsize "BUNFMT, 
bn->T->hash?bn->T->hash->heap->size:0);
+                               printf("\n");
+                               BBPunfix(bn->batCacheid);
+                       }
+               }
+       }
+
+       r = BATnew(TYPE_str,TYPE_bat,1);
+       BUNins(r, "schema", &sch->batCacheid, FALSE);
+       BUNins(r, "table", &tab->batCacheid, FALSE);
+       BUNins(r, "column", &col->batCacheid, FALSE);
+       BUNins(r, "location", &loc->batCacheid, FALSE);
+       BUNins(r, "cnt", &cnt->batCacheid, FALSE);
+       BUNins(r, "cap", &cap->batCacheid, FALSE);
+       BUNins(r, "width", &atom->batCacheid, FALSE);
+       BUNins(r, "size", &size->batCacheid, FALSE);
+       BUNins(r, "auxsize", &aux->batCacheid, FALSE);
+       BBPunfix(sch->batCacheid);
+       BBPunfix(tab->batCacheid);
+       BBPunfix(col->batCacheid);
+       BBPunfix(loc->batCacheid);
+       BBPunfix(cnt->batCacheid);
+       BBPunfix(cap->batCacheid);
+       BBPunfix(atom->batCacheid);
+       BBPunfix(size->batCacheid);
+       BBPunfix(aux->batCacheid);
+       BBPkeepref(*res = r->batCacheid);
+       return MAL_SUCCEED;
+}
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to