Changeset: 83cf2ee92ce3 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=83cf2ee92ce3
Modified Files:
        monetdb5/modules/mal/orderidx.c
        monetdb5/modules/mal/orderidx.h
        sql/test/orderidx/Tests/smalltable.sql
Branch: leftmart
Log Message:

A few minor issues


diffs (142 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
@@ -7,7 +7,7 @@
  */
 
 /*
- * (c) Martin Kersten
+ * (c) Martin Kersten, Lefteris Sidirourgos
  * Implement a parallel sort-merge MAL program generator
  */
 #include "monetdb_config.h"
@@ -33,24 +33,25 @@ OIDXcreateImplementation(Client cntxt, i
 
        if( pieces < 0 ){
                /* TODO estimate number of pieces */
-               pieces = 3;
+               pieces = 3; // should become GDKnr_threads
        }
-       if ( BATcount(b) < MIN_PIECE)
+       if ( BATcount(b) < MIN_PIECE || BATcount(b) <= (BUN) pieces)
                pieces = 1;
-       else
-       if ( BATcount(b) <= (BUN) pieces ){
-               pieces = BATcount(b);
-       }
 #ifdef _DEBUG_OIDX_
        mnstr_printf(cntxt->fdout,"#bat.orderidx pieces %d\n",pieces);
+       mnstr_printf(cntxt->fdout,"#oidx ttype %d bat %d\n", b->ttype,tpe);
 #endif
+       /* check if b already has index */
+       if( b->torderidx.flags )
+               return MAL_SUCCEED;
+       /* check if b is sorted, then index does nto make sense, other action  
is needed*/
+       if( b->tsorted || b->trevsorted)
+               return MAL_SUCCEED;
+       /* check if b is view and parent has index do a range select */
+    if (VIEWtparent(b)  && b->torderidx.flags)
+               return MAL_SUCCEED;
 
-       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 */
-
-       // create a temporary MAL function
+       // create a temporary MAL function to sort the BAT in parallel
        snprintf(name, IDLENGTH, "sort%d", rand()%1000);
        snew = newFunction(putName("user", 4), putName(name, strlen(name)), 
FUNCTIONsymbol);
        smb = snew->def;
@@ -102,7 +103,7 @@ OIDXcreateImplementation(Client cntxt, i
                q = pushBit(smb, q, 1);
                pack->argv[2+i] = getArg(q, 0);
        }
-       // finalize, check, and evaluate
+       // finalize OID packing, check, and evaluate
        pushInstruction(smb,pack);
        q = newAssignment(smb);
        q->barrier = EXITsymbol;
@@ -112,7 +113,7 @@ OIDXcreateImplementation(Client cntxt, i
        if (smb->errors) {
                msg = createException(MAL, "bat.orderidx", "Type errors in 
generated code");
        } else {
-               // evaluate MAL block
+               // evaluate MAL block and keep the ordered OID bat
                newstk = prepareMALstack(smb, smb->vsize);
                newstk->up = 0;
                newstk->stk[arg].vtype= TYPE_bat;
@@ -121,7 +122,7 @@ OIDXcreateImplementation(Client cntxt, i
         msg = runMALsequence(cntxt, smb, 1, 0, newstk, 0, 0);
                freeStack(newstk);
        }
-#ifdef _DEBUG_INDEX_
+#ifdef _DEBUG_OIDX_
        printFunction(cntxt->fdout, smb, 0, LIST_MAL_ALL);
 #endif
        // get rid of temporary MAL block
@@ -136,7 +137,6 @@ OIDXcreate(Client cntxt, MalBlkPtr mb, M
        str msg= MAL_SUCCEED;
        int pieces = -1;
 
-
        if (pci->argc == 3) {
                pieces = stk->stk[pci->argv[2]].val.ival;
                if (pieces < 0)
@@ -172,6 +172,10 @@ OIDXgetorderidx(Client cntxt, MalBlkPtr 
        return MAL_SUCCEED;
 }
 
+/*
+ * Merge the collection of sorted OID BATs into one
+ */
+
 str
 OIDXmerge(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
@@ -250,9 +254,9 @@ OIDXmerge(Client cntxt, MalBlkPtr mb, Ma
                oid *mv;
                BUN m_sz;
 
-               for (i=0, m_sz = 0; i < n_ar; i++) {
+               for (i=0, m_sz = 0; i < n_ar; i++) 
                        m_sz += BATcount(a[i]);
-               }
+               
                m = BATnew(TYPE_void, TYPE_oid, m_sz, TRANSIENT);
                if (m == NULL) {
                        for (i = 0; i < n_ar; i++)
@@ -300,9 +304,7 @@ do {                                                        
                                                                                
        \
 #endif
                        case TYPE_flt: BINARY_MERGE(flt); break;
                        case TYPE_dbl: BINARY_MERGE(dbl); break;
-                       case TYPE_void:
                        case TYPE_str:
-                       case TYPE_ptr:
                        default:
                                /* TODO: support strings, date, timestamps etc. 
*/
                                throw(MAL, "bat.orderidx", TYPE_NOT_SUPPORTED);
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
@@ -25,7 +25,7 @@
 #define orderidx_export extern
 #endif
 
-#define _DEBUG_OIDX_
+//#define _DEBUG_OIDX_
 orderidx_export str OIDXcreate(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci);
 orderidx_export str OIDXcreateImplementation(Client cntxt, int tpe, BAT *b, 
int pieces);
 orderidx_export str OIDXmerge(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci);
diff --git a/sql/test/orderidx/Tests/smalltable.sql 
b/sql/test/orderidx/Tests/smalltable.sql
--- a/sql/test/orderidx/Tests/smalltable.sql
+++ b/sql/test/orderidx/Tests/smalltable.sql
@@ -12,6 +12,6 @@ call orderidx('sys','xtmp3','i');
 select * from storage where "table"= 'xtmp3';
 select * from xtmp3 where i>=0 and i <8;
 
-destroy table xtmp2;
-destroy table xtmp3;
+drop table xtmp2;
+drop table xtmp3;
 
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to