Update of /cvsroot/monetdb/sql/src/backends/monet5
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv15984/src/backends/monet5

Modified Files:
        sql.mx sql_gencode.mx 
Log Message:
added support for sql/xml namespaces
fixed bug in algebra version for handling exist/not exists in exists/not exists
with correlation 

added optimizer steps for algebra version to rewrite semi/anti joins followed
by joins on the same (referenced) relation into a single semijoin
push selects through semi/anti joins

approved tests



U sql_gencode.mx
Index: sql_gencode.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/sql_gencode.mx,v
retrieving revision 1.289
retrieving revision 1.290
diff -u -d -r1.289 -r1.290
--- sql_gencode.mx      10 Oct 2008 08:54:31 -0000      1.289
+++ sql_gencode.mx      28 Oct 2008 20:05:04 -0000      1.290
@@ -1267,7 +1267,14 @@
                        int l = _dumpstmt(sql, mb, s->op1.stval);
 
                        backend_create_func(sql, s->op4.funcval->func); 
-                       if (s->op1.stval->nrcols) {
+                       if (s->op1.stval->nrcols && strcmp(fimp, "not_uniques") 
== 0) {
+                               int rtype = s->op4.funcval->res.type->localtype;
+
+                               q = newStmt(mb, mod, fimp);
+                               setVarType(mb,getArg(q,0), 
newBatType(TYPE_oid,rtype));
+                               setVarUDFtype(mb,getArg(q,0));
+                               q = pushArgument(mb, q, l);
+                       } else if (s->op1.stval->nrcols) {
                                int rtype = s->op4.funcval->res.type->localtype;
 
                                q = newStmt(mb, "mal","multiplex");

U sql.mx
Index: sql.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/sql.mx,v
retrieving revision 1.289
retrieving revision 1.290
diff -u -d -r1.289 -r1.290
--- sql.mx      10 Oct 2008 08:54:23 -0000      1.289
+++ sql.mx      28 Oct 2008 20:05:04 -0000      1.290
@@ -230,8 +230,12 @@
 command not_unique( b:bat[:oid,:oid]) :bit 
 address not_unique 
 comment "check if the tail sorted bat b doesn't have unique tail values" ;
-command not_unique( b:bat[:oid,:oid]) :bit 
-address not_unique ;
+
+command not_uniques( b:bat[:oid,:oid]) :bat[:oid,:oid] 
+address not_unique_oids 
+comment "return not unique oids" ;
+command not_uniques( b:bat[:oid,:wrd]) :bat[:oid,:oid] 
+address not_unique_oids ;
 
 function sql_environment():bat[:str,:bat];
        b := bat.new(:str,:bat,2);
@@ -758,6 +762,7 @@
 sql5_export str mvc_restart_seq(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci);
 sql5_export str zero_or_one(ptr ret, int *bid);
 sql5_export str not_unique(bit *ret, int *bid);
+sql5_export str not_unique_oids(bat *ret, bat *bid);
 sql5_export str month_interval_str( int *ret, str *s, int *ek, int *sk );
 sql5_export str second_interval_str( lng *res, str *s, int *ek, int *sk );
 sql5_export str dump_cache(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci);
@@ -2096,6 +2101,96 @@
        return MAL_SUCCEED;
 }
 
+/* later we could optimize this to start from current BUN 
+   And only search the from the first if second is not found.
+ */
+inline int 
+HASHfndTwice(BAT *b, ptr v)
+{
+       BATiter bi = bat_iterator(b);
+       BUN i = BUN_NONE;
+       int first = 1;
+       
+       HASHloop( bi, b->H->hash, i, v) {
+               if (!first)
+                       return 1;
+               first = 0;
+       }
+       return 0;
+}
+
+str 
+not_unique_oids(bat *ret, bat* bid) 
+{
+       BAT *b, *bn = NULL;
+
+       if ((b = BATdescriptor(*bid)) == NULL) {
+               throw(SQL, "not_uniques", "Cannot access descriptor");
+       }
+       if (b->ttype != TYPE_oid && b->ttype != TYPE_wrd) {
+               throw(SQL, "not_uniques", "Wrong types");
+       }
+
+       assert(b->htype == TYPE_oid);
+       if (BATtkey(b) || BATtdense(b) || BATcount(b) <= 1) {
+               bn = BATnew(TYPE_oid, TYPE_oid, 0);
+       } else if (b->tsorted&1) { /* ugh handle both wrd and oid types */
+               oid c = *(oid*)Tloc(b, BUNfirst(b)), *rf, *rh, *rt;
+               oid *h = (oid*)Hloc(b,0), *vp, *ve;
+               int first = 1;
+
+               bn = BATnew(TYPE_oid, TYPE_oid, BATcount(b));
+               vp = (oid*)Tloc(b, BUNfirst(b));
+               ve = vp + BATcount(b);
+               rf = rh = (oid*)Hloc(bn, BUNfirst(bn));
+               rt = (oid*)Tloc(bn, BUNfirst(bn));
+               *rh++ = *h++; 
+               *rt++ = *vp; 
+               for(vp++; vp < ve; vp++, h++) {
+                       oid v = *vp;
+                       if (v == c) {
+                               first = 0;
+                               *rh++ = *h;
+                               *rt++ = v;
+                       } else if (!first) {
+                               first = 1;
+                               *rh++ = *h;
+                               *rt++ = v;
+                       } else {
+                               *rh = *h;
+                               *rt = v;
+                       }
+                       c = v;
+               }
+               if (first)
+                       rh--;
+               BATsetcount(bn, rh - rf); 
+       } else {
+               oid *rf, *rh, *rt;
+               oid *h = (oid*)Hloc(b,0), *vp, *ve;
+               BAT *bm = BATmirror(b);
+
+               if (BATprepareHash(bm))
+                       throw(SQL, "not_uniques", "hash creation failed");
+               bn = BATnew(TYPE_oid, TYPE_oid, BATcount(b));
+               vp = (oid*)Tloc(b, BUNfirst(b));
+               ve = vp + BATcount(b);
+               rf = rh = (oid*)Hloc(bn, BUNfirst(bn));
+               rt = (oid*)Tloc(bn, BUNfirst(bn));
+               for(; vp < ve; vp++, h++) {
+                       /* try to find value twice */
+                       if (HASHfndTwice(bm, vp)) {
+                               *rh++ = *h;
+                               *rt++ = *vp;
+                       }
+               }
+               BATsetcount(bn, rh - rf); 
+       }
+       BBPunfix(b->batCacheid);
+       BBPkeepref(*ret = bn->batCacheid);
+       return MAL_SUCCEED;
+}
+
 static str
 voidbathash(bat *res, BAT *b )
 {


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to