Changeset: a3683c6001dd for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a3683c6001dd Modified Files: monetdb5/modules/mal/orderidx.c monetdb5/modules/mal/orderidx.h sql/backends/monet5/sql.c sql/backends/monet5/sql.h sql/backends/monet5/sql.mal sql/backends/monet5/sql_upgrades.c sql/scripts/18_index.sql sql/scripts/75_storagemodel.sql Branch: leftmart Log Message:
merge diffs (truncated from 333 to 300 lines): diff --git a/monetdb5/modules/mal/orderidx.c b/monetdb5/modules/mal/orderidx.c --- a/monetdb5/modules/mal/orderidx.c +++ b/monetdb5/modules/mal/orderidx.c @@ -15,16 +15,14 @@ #include "gdk.h" str -OIDXcreate(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) +OIDXcreateImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, BAT *b) { - int pieces = 3; - int i, loopvar, bid, arg; + int i, loopvar, arg, pieces; BUN cnt, step=0,o; MalBlkPtr smb; MalStkPtr newstk; Symbol snew; InstrPtr q, pack; - BAT *b; char name[IDLENGTH]; str msg= MAL_SUCCEED; @@ -40,11 +38,6 @@ OIDXcreate(Client cntxt, MalBlkPtr mb, M if (pieces < 0) throw(MAL,"bat.orderidx","Positive number expected"); - bid = *getArgReference_bat(stk, pci, 1); - b = BATdescriptor(bid); - if (b == NULL) - throw(MAL, "bat.orderidx", RUNTIME_OBJECT_MISSING); - /* TODO: check if b already has index */ /* TODO: check if b is sorted, then index does nto make sense, other action is needed*/ /* TODO: check if b is view and parent has index do a range select */ @@ -119,16 +112,29 @@ OIDXcreate(Client cntxt, MalBlkPtr mb, M msg = runMALsequence(cntxt, smb, 1, 0, newstk, 0, 0); freeStack(newstk); } + printFunction(cntxt->fdout, smb, 0, LIST_MAL_ALL); #ifdef _DEBUG_INDEX_ - printFunction(cntxt->fdout, smb, 0, LIST_MAL_ALL); #endif - BBPunfix(b->batCacheid); // get rid of temporary MAL block freeSymbol(snew); return msg; } str +OIDXcreate(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) +{ + BAT *b; + str msg= MAL_SUCCEED; + + b = BATdescriptor( *getArgReference_bat(stk, pci, 1)); + if (b == NULL) + throw(MAL, "bat.orderidx", RUNTIME_OBJECT_MISSING); + msg = OIDXcreateImplementation(cntxt,mb,stk,pci, b); + BBPunfix(b->batCacheid); + return msg; +} + +str OIDXgetorderidx(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) { BAT *b; diff --git a/monetdb5/modules/mal/orderidx.h b/monetdb5/modules/mal/orderidx.h --- a/monetdb5/modules/mal/orderidx.h +++ b/monetdb5/modules/mal/orderidx.h @@ -27,6 +27,7 @@ #define _DEBUG_OIDX_ orderidx_export str OIDXcreate(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); +orderidx_export str OIDXcreateImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, BAT *b); orderidx_export str OIDXmerge(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); orderidx_export str OIDXgetorderidx(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); #endif /* _OIDX_H */ 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 @@ -33,6 +33,7 @@ #include <opt_pipes.h> #include "clients.h" #include "mal_instruction.h" +#include "orderidx.h" static int rel_is_table(sql_rel *rel) @@ -4384,7 +4385,7 @@ SQLargRecord(Client cntxt, MalBlkPtr mb, /* Experimental code for dealing with oid indices */ str -SQLoidindex(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) +SQLorderidx(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) { str *sch = getArgReference_str(stk, pci, 1); str *tbl = getArgReference_str(stk, pci, 2); @@ -4394,7 +4395,8 @@ SQLoidindex(Client cntxt, MalBlkPtr mb, sql_table *t; sql_column *c; mvc *m = NULL; - str msg; + BAT *b; + str msg = MAL_SUCCEED; if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL) return msg; @@ -4402,19 +4404,23 @@ SQLoidindex(Client cntxt, MalBlkPtr mb, return msg; s = mvc_bind_schema(m, *sch); if (s == NULL) - throw(SQL, "sql.oidindex", "3F000!Schema missing"); + throw(SQL, "sql.orderidx", "3F000!Schema missing"); t = mvc_bind_table(m, s, *tbl); if (t == NULL) - throw(SQL, "sql.oidindex", "42S02!Table missing"); + throw(SQL, "sql.orderidx", "42S02!Table missing"); c = mvc_bind_column(m, t, *col); if (c == NULL) - throw(SQL, "sql.oidindex", "42S02!Column missing"); + throw(SQL, "sql.orderidx", "42S02!Column missing"); tr = m->session->tr; t->base.wtime = s->base.wtime = tr->wtime = tr->wstime; t->base.rtime = s->base.rtime = tr->rtime = tr->stime; mnstr_printf(cntxt->fdout, "#About to create the oid index on %s.%s.%s\n", *sch, *tbl, *col); - - return MAL_SUCCEED; + b = store_funcs.bind_col(tr, c, RDONLY); + if( b == NULL) + throw(SQL,"sql.orderidx","Can not access descriptor"); + msg= OIDXcreateImplementation(cntxt,mb,stk,pci, b); + BBPunfix(b->batCacheid); + return msg; } /* @@ -4660,7 +4666,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; + BAT *sch, *tab, *col, *type, *loc, *cnt, *atom, *size, *heap, *indices, *phash, *sort, *imprints, *mode, *oidx; mvc *m = NULL; str msg; sql_trans *tr; @@ -4681,6 +4687,7 @@ sql_storage(Client cntxt, MalBlkPtr mb, bat *rphash = getArgReference_bat(stk, pci, 11); bat *rimprints = getArgReference_bat(stk, pci, 12); bat *rsort = getArgReference_bat(stk, pci, 13); + bat *roidx = getArgReference_bat(stk, pci, 14); if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL) return msg; @@ -4716,10 +4723,12 @@ sql_storage(Client cntxt, MalBlkPtr mb, BATseqbase(imprints, 0); sort = BATnew(TYPE_void, TYPE_bit, 0, TRANSIENT); BATseqbase(sort, 0); + oidx = BATnew(TYPE_void, TYPE_lng, 0, TRANSIENT); + BATseqbase(oidx, 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 || phash == NULL) { + sort == NULL || cnt == NULL || atom == NULL || size == NULL || heap == NULL || indices == NULL || phash == NULL || oidx == NULL) { if (sch) BBPunfix(sch->batCacheid); if (tab) @@ -4748,6 +4757,8 @@ sql_storage(Client cntxt, MalBlkPtr mb, BBPunfix(imprints->batCacheid); if (sort) BBPunfix(sort->batCacheid); + if (oidx) + BBPunfix(oidx->batCacheid); throw(SQL, "sql.storage", MAL_MALLOC_FAIL); } for (nsch = tr->schemas.set->h; nsch; nsch = nsch->next) { @@ -4836,6 +4847,9 @@ sql_storage(Client cntxt, MalBlkPtr mb, w = BATtordered(bn); BUNappend(sort, &w, FALSE); + + sz = 0; + BUNappend(oidx, &sz, FALSE); BBPunfix(bn->batCacheid); } @@ -4915,6 +4929,8 @@ sql_storage(Client cntxt, MalBlkPtr mb, /*printf("\n"); */ w = BATtordered(bn); BUNappend(sort, &w, FALSE); + sz = 0; + BUNappend(oidx, &sz, FALSE); BBPunfix(bn->batCacheid); } } @@ -4936,6 +4952,7 @@ sql_storage(Client cntxt, MalBlkPtr mb, BBPkeepref(*rphash = phash->batCacheid); BBPkeepref(*rimprints = imprints->batCacheid); BBPkeepref(*rsort = sort->batCacheid); + BBPkeepref(*roidx = oidx->batCacheid); return MAL_SUCCEED; } diff --git a/sql/backends/monet5/sql.h b/sql/backends/monet5/sql.h --- a/sql/backends/monet5/sql.h +++ b/sql/backends/monet5/sql.h @@ -130,7 +130,7 @@ sql5_export str SQLdrop_hash(Client cntx sql5_export str SQLnewDictionary(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); sql5_export str SQLdropDictionary(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); sql5_export str SQLargRecord(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); -sql5_export str SQLoidindex(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); +sql5_export str SQLorderidx(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); sql5_export str SQLoptimizersUpdate(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); sql5_export str month_interval_str(int *ret, const str *s, const int *ek, const int *sk); sql5_export str second_interval_str(lng *res, const str *s, const int *ek, const int *sk); 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,7 +462,8 @@ pattern storage()( hashes:bat[:oid,:lng], phash:bat[:oid,:bit], imprints:bat[:oid,:lng], - sorted:bat[:oid,:bit]) + sorted:bat[:oid,:bit], + orderidx:bat[:oid,:lng]) address sql_storage comment "return a table with storage information "; @@ -566,9 +567,9 @@ command batcalc.hash( b:bat[:oid,:any_1] pattern calc.rotate_xor_hash(h:wrd, nbits:int, v:any_1) :wrd address MKEYrotate_xor_hash; command batcalc.rotate_xor_hash(h:bat[:oid,:wrd], nbits:int, b:bat[:oid,:any_1]) :bat[:oid,:int] address MKEYbulk_rotate_xor_hash; -pattern oidindex(sch:str,tab:str,col:str) -address SQLoidindex -comment "Create an oid index on a particular column"; +pattern orderidx(sch:str,tab:str,col:str) +address SQLorderidx +comment "Create an ordered oid index on a particular column"; command sql.dec_round( v:bte, r:bte ) :bte address bte_dec_round_wrap 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 @@ -1348,7 +1348,7 @@ sql_update_jul2015(Client c) "drop function sys.columnsize;\n" "drop function sys.storage;\n" "create function sys.storage()\n" - "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)\n" + "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, orderidx bigint)\n" "external name sql.storage;\n" "create view sys.storage as select * from sys.storage();\n" "create function sys.columnsize(nme string, i bigint, d bigint)\n" @@ -1402,14 +1402,15 @@ sql_update_jul2015(Client c) " heapsize bigint,\n" " hashes bigint,\n" " imprints bigint,\n" - " sorted boolean)\n" + " sorted boolean," + " orderidx bigint)\n" "begin\n" " return select I.\"schema\", I.\"table\", I.\"column\", I.\"type\", I.\"count\",\n" " columnsize(I.\"type\", I.count, I.\"distinct\"),\n" " heapsize(I.\"type\", I.\"distinct\", I.\"atomwidth\"),\n" " hashsize(I.\"reference\", I.\"count\"),\n" " imprintsize(I.\"count\",I.\"type\"),\n" - " I.sorted\n" + " I.sorted, I.orderidx\n" " from sys.storagemodelinput I;\n" "end;\n" "create view sys.storagemodel as select * from sys.storagemodel();\n" diff --git a/sql/scripts/18_index.sql b/sql/scripts/18_index.sql --- a/sql/scripts/18_index.sql +++ b/sql/scripts/18_index.sql @@ -6,7 +6,7 @@ -- Experimental oid index -create procedure oidindex(sys string, tab string, col string) - external name sql.oidindex; +create procedure orderidx(sys string, tab string, col string) + external name sql.orderidx; 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, phash boolean, 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, orderidx bigint) external name sql."storage"; create view sys."storage" as select * from sys."storage"(); @@ -36,7 +36,8 @@ create table sys.storagemodelinput( "distinct" bigint, -- indication of distinct number of strings "atomwidth" int, -- average width of strings or clob "reference" boolean, -- used as foreign key reference _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list