Changeset: 6d1ac8c875f9 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6d1ac8c875f9
Modified Files:
        monetdb5/modules/atoms/mtime.c
        monetdb5/optimizer/opt_remap.c
        sql/backends/monet5/rel_bin.c
        
sql/test/BugTracker-2019/Tests/duplicates-not-eliminated-long-CASE-stmt.Bug-6697.stable.out
        
sql/test/BugTracker-2019/Tests/duplicates-not-eliminated-long-CASE-stmt.Bug-6697.stable.out.single
Branch: clean-candidates
Log Message:

Added candidate list support to mtime module. I think candidates are being 
pushed


diffs (truncated from 2729 to 300 lines):

diff --git a/monetdb5/modules/atoms/mtime.c b/monetdb5/modules/atoms/mtime.c
--- a/monetdb5/modules/atoms/mtime.c
+++ b/monetdb5/modules/atoms/mtime.c
@@ -32,6 +32,8 @@
 #include "gdk.h"
 #include "gdk_time.h"
 #include "mtime.h"
+#include "mal_client.h"
+#include "mal_interpreter.h"
 #include "mal_exception.h"
 
 #ifndef HAVE_STRPTIME
@@ -85,9 +87,7 @@ MTIMEcurrent_timestamp(timestamp *ret)
 
 #define APPEND_VAR(MALFUNC) dst[i] = res;
 
-#define GET_NEXT_VAR(VAR) VAR[i]
-
-#define GET_NEXT_VAR_CAND(VAR) VAR[p]
+#define GET_NEXT_VAR(VAR, OFF) VAR[OFF]
 
 #define INIT_ITER(VAR, VAR_BAT) VAR = bat_iterator(VAR_BAT)
 
@@ -97,9 +97,7 @@ MTIMEcurrent_timestamp(timestamp *ret)
                break; \
        } \
 
-#define GET_NEXT_ITER(VAR) BUNtvar(VAR, i)
-
-#define GET_NEXT_ITER_CAND(VAR) BUNtvar(VAR, p)
+#define GET_NEXT_ITER(VAR, OFF) BUNtvar(VAR, OFF)
 
 #define DEC_NOTHING(A, B) ;
 
@@ -120,93 +118,48 @@ bailout: \
 
 #define COPYFLAGS      do { bn->tsorted = b1->tsorted; bn->trevsorted = 
b1->trevsorted; } while (0)
 #define SETFLAGS       do { bn->tsorted = bn->trevsorted = n < 2; } while (0)
-#define func1(NAME, NAMEBULK, MALFUNC, INTYPE, OUTTYPE, FUNC, SETFLAGS, 
FUNC_CALL, DEC_SRC, DEC_OUTPUT, \
-                         INIT_SRC, INIT_OUTPUT, GET_NEXT_SRC)  \
+#define func1(NAME, MALFUNC, INTYPE, OUTTYPE, FUNC, SETFLAGS, FUNC_CALL, 
DEC_SRC, DEC_OUTPUT, \
+                         INIT_SRC, INIT_OUTPUT, GET_NEXT_SRC)          \
 static str                                                                     
                                                        \
 NAME(OUTTYPE *ret, const INTYPE *src)                                          
                        \
 {                                                                              
                                                                \
        str msg = MAL_SUCCEED;                                                  
                                        \
        do {                                                                    
                                                        \
-               FUNC_CALL(FUNC, (*ret), *src);                                  
                                \
+               FUNC_CALL(FUNC, (*ret), *src)                                   
                                \
        } while (0);                                                            
                                                \
        return msg;                                                             
                                                        \
 }                                                                              
                                                                \
 static str                                                                     
                                                        \
-NAMEBULK(bat *ret, const bat *bid)                                             
                                \
+NAME##_bulk(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)   \
 {                                                                              
                                                                \
-       BAT *b1 = NULL, *bn = NULL;                                             
                                        \
+       str msg = MAL_SUCCEED;                                                  
                                        \
+       BAT *b1 = NULL, *s = NULL, *bn = NULL;                                  
                        \
        BUN n;                                                                  
                                                        \
+       struct canditer ci = {0};                                               
                                        \
+       oid off;                                                                
                                                        \
+       bool nils = false;                                                      
                                                \
+       bat *ret = getArgReference_bat(stk, pci, 0),                            
                \
+               *bid = getArgReference_bat(stk, pci, 1),                        
                        \
+               *sid = pci->argc == 3 ? getArgReference_bat(stk, pci, 2) : 
NULL;\
        DEC_SRC(INTYPE, src1);                                                  
                                        \
        DEC_OUTPUT(OUTTYPE, dst);                                               
                                        \
-       str msg = MAL_SUCCEED;                                                  
                                        \
                                                                                
                                                                \
+       (void) cntxt;                                                           
                                                \
+       (void) mb;                                                              
                                                        \
        if ((b1 = BATdescriptor(*bid)) == NULL) {                               
                        \
                msg = createException(MAL, "batmtime." MALFUNC,                 
                \
                          SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);              
                        \
                goto bailout;                                                   
                                                \
        }                                                                       
                                                                \
-       n = BATcount(b1);                                                       
                                                \
-       if ((bn = COLnew(b1->hseqbase, TYPE_##OUTTYPE, n, TRANSIENT)) == NULL) 
{ \
-               msg = createException(MAL, "batmtime." MALFUNC,                 
                \
-                         SQLSTATE(HY013) MAL_MALLOC_FAIL);                     
                        \
-               goto bailout;                                                   
                                                \
-       }                                                                       
                                                                \
-       INIT_SRC(src1, b1);                                                     
                                                \
-       INIT_OUTPUT(dst, bn);                                                   
                                        \
-       for (BUN i = 0; i < n; i++) {                                           
                                \
-               FUNC_CALL(FUNC, (dst[i]), (GET_NEXT_SRC(src1)));                
                \
-       }                                                                       
                                                                \
-       bn->tnonil = b1->tnonil;                                                
                                        \
-       bn->tnil = b1->tnil;                                                    
                                        \
-       BATsetcount(bn, n);                                                     
                                                \
-       SETFLAGS;                                                               
                                                        \
-       bn->tkey = false;                                                       
                                                \
-bailout:                                                                       
                                                        \
-       if (b1)                                                                 
                                                        \
-               BBPunfix(b1->batCacheid);                                       
                                        \
-       if (msg && bn)                                                          
                                                \
-               BBPreclaim(bn);                                                 
                                                \
-       else if (bn)                                                            
                                                \
-               BBPkeepref(*ret = bn->batCacheid);                              
                                \
-       return msg;                                                             
                                                        \
-}
-#define func1_cand(NAME, MALFUNC, INTYPE, OUTTYPE, FUNC, SETFLAGS, FUNC_CALL, 
DEC_SRC, \
-                                  DEC_OUTPUT, INIT_SRC, INIT_OUTPUT, 
GET_NEXT_SRC)             \
-static str                                                                     
                                                        \
-NAME(OUTTYPE *ret, const INTYPE *src)                                          
                        \
-{                                                                              
                                                                \
-       str msg = MAL_SUCCEED;                                                  
                                        \
-       do {                                                                    
                                                        \
-               FUNC_CALL(FUNC, (*ret), *src);                                  
                                \
-       } while (0);                                                            
                                                \
-       return msg;                                                             
                                                        \
-}                                                                              
                                                                \
-static str                                                                     
                                                        \
-NAME##_bulk(bat *ret, const bat *bid, const bat *sid)                          
        \
-{                                                                              
                                                                \
-       str msg = MAL_SUCCEED;                                                  
                                        \
-       BAT *b1 = NULL, *s = NULL, *bn = NULL;                                  
                        \
-       BUN n;                                                                  
                                                        \
-       DEC_SRC(INTYPE, src1);                                                  
                                        \
-       DEC_OUTPUT(OUTTYPE, dst);                                               
                                        \
-       struct canditer ci;                                                     
                                                \
-       oid off;                                                                
                                                        \
-       bool nils = false;                                                      
                                                \
-                                                                               
                                                                \
-       if ((b1 = BATdescriptor(*bid)) == NULL) {                               
                        \
-               msg = createException(MAL, "batmtime." MALFUNC "_cand",         
        \
-                         SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);              
                        \
-               goto bailout;                                                   
                                                \
-       }                                                                       
                                                                \
        if (sid && !is_bat_nil(*sid) && (s = BATdescriptor(*sid)) == NULL) {\
-               msg = createException(MAL, "batmtime." MALFUNC "_cand",         
        \
+               msg = createException(MAL, "batmtime." MALFUNC,                 
                \
                          SQLSTATE(HY005) RUNTIME_OBJECT_MISSING);              
                        \
                goto bailout;                                                   
                                                \
        }                                                                       
                                                                \
        off = b1->hseqbase;                                                     
                                                \
        n = canditer_init(&ci, b1, s);                                          
                                \
        if ((bn = COLnew(ci.hseq, TYPE_##OUTTYPE, n, TRANSIENT)) == NULL) { \
-               msg = createException(MAL, "batmtime." MALFUNC "_cand",         
        \
+               msg = createException(MAL, "batmtime." MALFUNC,                 
                \
                          SQLSTATE(HY013) MAL_MALLOC_FAIL);                     
                        \
                goto bailout;                                                   
                                                \
        }                                                                       
                                                                \
@@ -214,14 +167,14 @@ NAME##_bulk(bat *ret, const bat *bid, co
        INIT_OUTPUT(dst, bn);                                                   
                                        \
        if (ci.tpe == cand_dense) {                                             
                                        \
                for (BUN i = 0; i < n; i++) {                                   
                                \
-                       BUN p = (BUN) (canditer_next_dense(&ci) - off);         
                \
-                       FUNC_CALL(FUNC, (dst[i]), (GET_NEXT_SRC(src1)));        
                \
+                       oid p = (BUN) (canditer_next_dense(&ci) - off);         
                \
+                       FUNC_CALL(FUNC, dst[i], GET_NEXT_SRC(src1, p))          
                \
                        nils |= is_##OUTTYPE##_nil(dst[i]);                     
                                \
                }                                                               
                                                                \
        } else {                                                                
                                                        \
                for (BUN i = 0; i < n; i++) {                                   
                                \
-                       BUN p = (BUN) (canditer_next(&ci) - off);               
                        \
-                       FUNC_CALL(FUNC, (dst[i]), (GET_NEXT_SRC(src1)));        
                \
+                       oid p = (BUN) (canditer_next(&ci) - off);               
                        \
+                       FUNC_CALL(FUNC, dst[i], GET_NEXT_SRC(src1, p))          
                \
                        nils |= is_##OUTTYPE##_nil(dst[i]);                     
                                \
                }                                                               
                                                                \
        }                                                                       
                                                                \
@@ -242,10 +195,10 @@ bailout:                                                  
                                                                        \
        return msg;                                                             
                                                        \
 }
 
-#define func1_noexcept(FUNC, RET, PARAM) RET = FUNC(PARAM)
+#define func1_noexcept(FUNC, RET, PARAM) RET = FUNC(PARAM);
 #define func1_except(FUNC, RET, PARAM) msg = FUNC(&RET, PARAM); if (msg) break;
 
-#define func2(NAME, NAMEBULK, MALFUNC, INTYPE1, INTYPE2, OUTTYPE, FUNC, 
FUNC_CALL, DEC_INPUT1, DEC_INPUT2, DEC_SRC1, DEC_SRC2, DEC_OUTPUT, DEC_EXTRA, \
+#define func2(NAME, MALFUNC, INTYPE1, INTYPE2, OUTTYPE, FUNC, FUNC_CALL, 
DEC_INPUT1, DEC_INPUT2, DEC_SRC1, DEC_SRC2, DEC_OUTPUT, DEC_EXTRA, \
                         INIT_SRC1, INIT_SRC2, INIT_OUTPUT, GET_NEXT_SRC1, 
GET_NEXT_SRC2, APPEND_NEXT, CLEAR_EXTRA_SINGLE, CLEAR_EXTRA_MULTI)   \
 static str                                                                     
                                                        \
 NAME(OUTTYPE *ret, const INTYPE1 *v1, const INTYPE2 *v2)                       
        \
@@ -254,22 +207,32 @@ NAME(OUTTYPE *ret, const INTYPE1 *v1, co
        DEC_EXTRA(OUTTYPE, res, MALFUNC);                                       
                                \
                                                                                
                                                                \
        do {                                                                    
                                                        \
-               FUNC_CALL(FUNC, res, *v1, *v2);                                 
                                \
+               FUNC_CALL(FUNC, res, *v1, *v2)                                  
                                \
        } while (0);                                                            
                                                \
        CLEAR_EXTRA_SINGLE(MALFUNC);                                            
                                \
        return msg;                                                             
                                                        \
 }                                                                              
                                                                \
 static str                                                                     
                                                        \
-NAMEBULK(bat *ret, const bat *bid1, const bat *bid2)                           
        \
+NAME##_bulk(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)   \
 {                                                                              
                                                                \
        str msg = MAL_SUCCEED;                                                  
                                        \
-       BAT *b1 = NULL, *b2 = NULL, *bn = NULL;                                 
                        \
+       BAT *b1 = NULL, *b2 = NULL, *s1 = NULL, *s2 = NULL, *bn = NULL;         
\
        BUN n;                                                                  
                                                        \
+       oid off1, off2;                                                         
                                                \
+       struct canditer ci1 = {0}, ci2 = {0};                                   
                        \
+       bool nils = false;                                                      
                                                \
+       bat *ret = getArgReference_bat(stk, pci, 0),                            
                \
+               *bid1 = getArgReference_bat(stk, pci, 1),                       
                        \
+               *bid2 = getArgReference_bat(stk, pci, 2),                       
                        \
+               *sid1 = pci->argc == 5 ? getArgReference_bat(stk, pci, 3) : 
NULL, \
+               *sid2 = pci->argc == 5 ? getArgReference_bat(stk, pci, 4) : 
NULL; \
        DEC_SRC1(INTYPE1, src1);                                                
                                        \
        DEC_SRC2(INTYPE2, src2);                                                
                                        \
        DEC_OUTPUT(OUTTYPE, dst);                                               
                                        \
        DEC_EXTRA(OUTTYPE, res, MALFUNC);                                       
                                \
                                                                                
                                                                \
+       (void) cntxt;                                                           
                                                \
+       (void) mb;                                                              
                                                        \
        b1 = BATdescriptor(*bid1);                                              
                                        \
        b2 = BATdescriptor(*bid2);                                              
                                        \
        if (b1 == NULL || b2 == NULL) {                                         
                                \
@@ -283,20 +246,51 @@ NAMEBULK(bat *ret, const bat *bid1, cons
                          "inputs not the same size");                          
                                \
                goto bailout;                                                   
                                                \
        }                                                                       
                                                                \
-       if ((bn = COLnew(b1->hseqbase, TYPE_##OUTTYPE, n, TRANSIENT)) == NULL) 
{ \
+       if (sid1 && !is_bat_nil(*sid1) && (s1 = BATdescriptor(*sid1)) == NULL) 
{ \
+               msg = createException(MAL, "batmtime." MALFUNC,                 
                \
+                         SQLSTATE(HY005) RUNTIME_OBJECT_MISSING);              
                        \
+               goto bailout;                                                   
                                                \
+       }                                                                       
                                                                \
+       if (sid2 && !is_bat_nil(*sid2) && (s2 = BATdescriptor(*sid2)) == NULL) 
{ \
+               msg = createException(MAL, "batmtime." MALFUNC,                 
                \
+                         SQLSTATE(HY005) RUNTIME_OBJECT_MISSING);              
                        \
+               goto bailout;                                                   
                                                \
+       }                                                                       
                                                                \
+       n = canditer_init(&ci1, b1, s1);                                        
                                \
+       if (canditer_init(&ci2, b2, s2) != n || ci1.hseq != ci2.hseq) {         
\
+               msg = createException(MAL, "batmtime." MALFUNC,                 
                \
+                         "inputs not the same size");                          
                                \
+               goto bailout;                                                   
                                                \
+       }                                                                       
                                                                \
+       if ((bn = COLnew(ci1.hseq, TYPE_##OUTTYPE, n, TRANSIENT)) == NULL) { \
                msg = createException(MAL, "batmtime." MALFUNC,                 
                \
                          SQLSTATE(HY013) MAL_MALLOC_FAIL);                     
                        \
                goto bailout;                                                   
                                                \
        }                                                                       
                                                                \
+       off1 = b1->hseqbase;                                                    
                                        \
+       off2 = b2->hseqbase;                                                    
                                        \
        INIT_SRC1(src1, b1);                                                    
                                        \
        INIT_SRC2(src2, b2);                                                    
                                        \
        INIT_OUTPUT(dst, bn);                                                   
                                        \
-       for (BUN i = 0; i < n; i++) {                                           
                                \
-               FUNC_CALL(FUNC, (res), (GET_NEXT_SRC1(src1)), 
(GET_NEXT_SRC2(src2)));   \
-               APPEND_NEXT(MALFUNC);                                           
                                        \
+       if (ci1.tpe == cand_dense && ci2.tpe == cand_dense) {                   
        \
+               for (BUN i = 0; i < n; i++) {                                   
                                \
+                       oid p1 = (BUN) (canditer_next_dense(&ci1) - off1);      
                \
+                       oid p2 = (BUN) (canditer_next_dense(&ci2) - off2);      
                \
+                       FUNC_CALL(FUNC, res, GET_NEXT_SRC1(src1, p1), 
GET_NEXT_SRC2(src2, p2))  \
+                       APPEND_NEXT(MALFUNC);                                   
                                        \
+                       nils |= is_##OUTTYPE##_nil(res);                        
                                \
+               }                                                               
                                                                \
+       } else {                                                                
                                                        \
+               for (BUN i = 0; i < n; i++) {                                   
                                \
+                       oid p1 = (BUN) (canditer_next(&ci1) - off1);            
                \
+                       oid p2 = (BUN) (canditer_next(&ci2) - off2);            
                \
+                       FUNC_CALL(FUNC, res, GET_NEXT_SRC1(src1, p1), 
GET_NEXT_SRC2(src2, p2))  \
+                       APPEND_NEXT(MALFUNC);                                   
                                        \
+                       nils |= is_##OUTTYPE##_nil(res);                        
                                \
+               }                                                               
                                                                \
        }                                                                       
                                                                \
-       bn->tnonil = b1->tnonil & b2->tnonil;                                   
                        \
-       bn->tnil = b1->tnil | b2->tnil;                                         
                                \
+       bn->tnonil = !nils;                                                     
                                                \
+       bn->tnil = nils;                                                        
                                                \
        BATsetcount(bn, n);                                                     
                                                \
        bn->tsorted = n < 2;                                                    
                                        \
        bn->trevsorted = n < 2;                                                 
                                        \
@@ -307,6 +301,10 @@ bailout:                                                   
                                                                        \
                BBPunfix(b1->batCacheid);                                       
                                        \
        if (b2)                                                                 
                                                        \
                BBPunfix(b2->batCacheid);                                       
                                        \
+       if (s1)                                                                 
                                                        \
+               BBPunfix(s1->batCacheid);                                       
                                        \
+       if (s2)                                                                 
                                                        \
+               BBPunfix(s2->batCacheid);                                       
                                        \
        if (msg && bn)                                                          
                                                \
                BBPreclaim(bn);                                                 
                                                \
        else if (bn)                                                            
                                                \
@@ -314,34 +312,60 @@ bailout:                                                  
                                                                        \
        return msg;                                                             
                                                        \
 }                                                                              
                                                                \
 static str                                                                     
                                                        \
-NAMEBULK##_p1(bat *ret, const DEC_INPUT1(INTYPE1, src1), const bat *bid2)      
\
+NAME##_bulk_p1(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)        
\
 {                                                                              
                                                                \
        str msg = MAL_SUCCEED;                                                  
                                        \
-       BAT *b2 = NULL, *bn = NULL;                                             
                                        \
+       BAT *b2 = NULL, *s2 = NULL, *bn = NULL;                                 
                        \
        BUN n;                                                                  
                                                        \
+       oid off2;                                                               
                                                        \
+       struct canditer ci2 = {0};                                              
                                        \
+       bool nils = false;                                                      
                                                \
+       bat *ret = getArgReference_bat(stk, pci, 0),                            
                \
+               *bid2 = getArgReference_bat(stk, pci, 2),                       
                        \
+               *sid2 = pci->argc == 4 ? getArgReference_bat(stk, pci, 3) : 
NULL; \
+       const DEC_INPUT1(INTYPE1, src1) = (INTYPE1*)getArgReference(stk, pci, 
1);       \
        DEC_SRC2(INTYPE2, src2);                                                
                                        \
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to