Changeset: f355ed2d4d4e for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f355ed2d4d4e
Added Files:
        sql/test/orderidx/Tests/All
        sql/test/orderidx/Tests/simpletable.sql
Modified Files:
        monetdb5/modules/mal/mal_init.mal
        monetdb5/modules/mal/orderidx.c
        monetdb5/modules/mal/orderidx.h
        sql/backends/monet5/sql.c
Branch: leftmart
Log Message:

Simple table ordered oid indx


diffs (158 lines):

diff --git a/monetdb5/modules/mal/mal_init.mal 
b/monetdb5/modules/mal/mal_init.mal
--- a/monetdb5/modules/mal/mal_init.mal
+++ b/monetdb5/modules/mal/mal_init.mal
@@ -31,7 +31,7 @@ include streams;
 include bat5;
 include batExtensions;
 include algebra;
-include arrange;
+include orderidx;
 #include calc; --- moved to autoload/01_calc
 include status;
 include groupby;
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,9 +15,9 @@
 #include "gdk.h"
 
 str
-OIDXcreateImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci, BAT *b)
+OIDXcreateImplementation(Client cntxt, int tpe, BAT *b, int pieces)
 {
-       int i, loopvar, arg, pieces;
+       int i, loopvar, arg;
        BUN cnt, step=0,o;
        MalBlkPtr smb;
        MalStkPtr newstk;
@@ -26,18 +26,15 @@ OIDXcreateImplementation(Client cntxt, M
        char name[IDLENGTH];
        str msg= MAL_SUCCEED;
 
-       if (pci->argc == 3) {
-               pieces = stk->stk[pci->argv[2]].val.ival;
-       } else {
-               /* TODO: educated guess needed on number of partitions */
+       if( pieces < 0){
+               /* TODO estimate number of pieces */
+               pieces = 3;
        }
 #ifdef _DEBUG_OIDX_
        mnstr_printf(cntxt->fdout,"#bat.orderidx pieces %d\n",pieces);
 #endif
 
-       if (pieces < 0)
-               throw(MAL,"bat.orderidx","Positive number expected");
-
+       mnstr_printf(cntxt->fdout,"#oidx ttype %d bat %d\n", b->ttype,tpe);
        /* 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 */
@@ -47,7 +44,7 @@ OIDXcreateImplementation(Client cntxt, M
        snew = newFunction(putName("user", 4), putName(name, strlen(name)), 
FUNCTIONsymbol);
        smb = snew->def;
        q = getInstrPtr(smb, 0);
-       arg = newTmpVariable(smb, getArgType(mb,pci,1));
+       arg = newTmpVariable(smb, tpe);
        pushArgument(smb, q, arg);
        getArg(q,0) = newTmpVariable(smb, TYPE_void);
 
@@ -72,7 +69,7 @@ OIDXcreateImplementation(Client cntxt, M
        for (i=0; i< pieces; i++) {
                // add slice instruction
                q = newStmt(smb, putName("algebra", 7),putName("slice", 5));
-               setVarType(smb, getArg(q,0), getArgType(mb, pci, 1));
+               setVarType(smb, getArg(q,0), tpe);
                setVarFixed(smb, getArg(q,0));
                q = pushArgument(smb, q, arg);
                pack = pushArgument(smb, pack, getArg(q,0));
@@ -107,13 +104,14 @@ OIDXcreateImplementation(Client cntxt, M
                // evaluate MAL block
                newstk = prepareMALstack(smb, smb->vsize);
                newstk->up = 0;
-               VALcopy(&newstk->stk[arg], &stk->stk[getArg(pci,1)]);
+               newstk->stk[arg].vtype= TYPE_bat;
+               newstk->stk[arg].val.bval= b->batCacheid;
                BBPincref(newstk->stk[arg].val.bval, TRUE);
         msg = runMALsequence(cntxt, smb, 1, 0, newstk, 0, 0);
                freeStack(newstk);
        }
+#ifdef _DEBUG_INDEX_
        printFunction(cntxt->fdout, smb, 0, LIST_MAL_ALL);
-#ifdef _DEBUG_INDEX_
 #endif
        // get rid of temporary MAL block
        freeSymbol(snew);
@@ -125,11 +123,19 @@ OIDXcreate(Client cntxt, MalBlkPtr mb, M
 {
        BAT *b;
        str msg= MAL_SUCCEED;
+       int pieces = -1;
+
+
+       if (pci->argc == 3) {
+               pieces = stk->stk[pci->argv[2]].val.ival;
+               if (pieces < 0)
+                       throw(MAL,"bat.orderidx","Positive number expected");
+       }
 
        b = BATdescriptor( *getArgReference_bat(stk, pci, 1));
        if (b == NULL)
                throw(MAL, "bat.orderidx", RUNTIME_OBJECT_MISSING);
-       msg = OIDXcreateImplementation(cntxt,mb,stk,pci, b);
+       msg = OIDXcreateImplementation(cntxt, getArgType(mb,pci,1), b, pieces);
        BBPunfix(b->batCacheid);
        return msg;
 }
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,7 +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 OIDXcreateImplementation(Client cntxt, int tpe, BAT *b, 
int pieces);
 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
@@ -4418,7 +4418,7 @@ SQLorderidx(Client cntxt, MalBlkPtr mb, 
        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);
+       msg=  
OIDXcreateImplementation(cntxt,newBatType(TYPE_oid,b->ttype),b,-1);
        BBPunfix(b->batCacheid);
     return msg;
 }
diff --git a/sql/test/orderidx/Tests/All b/sql/test/orderidx/Tests/All
new file mode 100644
--- /dev/null
+++ b/sql/test/orderidx/Tests/All
@@ -0,0 +1,1 @@
+simpletable
diff --git a/sql/test/orderidx/Tests/simpletable.sql 
b/sql/test/orderidx/Tests/simpletable.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/orderidx/Tests/simpletable.sql
@@ -0,0 +1,17 @@
+create table xtmp1( i integer);
+insert into xtmp1 values (1),(2),(4),(0);
+select * from xtmp;
+
+select * from storage where "table"= 'xtmp1';
+call orderidx('sys','xtmp1','i');
+
+select * from storage where "table"= 'xtmp1';
+
+select * from xtmp1 where i <0;
+select * from xtmp1 where i <1;
+select * from xtmp1 where i <2;
+select * from xtmp1 where i <5;
+select * from xtmp1 where i <8;
+
+select * from xtmp1 where i>=0 and i <8;
+select * from xtmp1 where i>=2 and i <=2;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to