Changeset: 3481b7fcd5e9 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/3481b7fcd5e9
Added Files:
        sql/test/BugTracker-2025/Tests/7726-commonterms.test
Modified Files:
        monetdb5/optimizer/opt_commonTerms.c
        sql/test/BugTracker-2025/Tests/All
Branch: Dec2025
Log Message:

fix for bug #7726, common terms should bail on bat.replace


diffs (58 lines):

diff --git a/monetdb5/optimizer/opt_commonTerms.c 
b/monetdb5/optimizer/opt_commonTerms.c
--- a/monetdb5/optimizer/opt_commonTerms.c
+++ b/monetdb5/optimizer/opt_commonTerms.c
@@ -27,13 +27,6 @@
 */
 
 __attribute__((__pure__))
-static inline bool
-isProjectConst(const InstrRecord *p)
-{
-       return (getModuleId(p) == algebraRef && getFunctionId(p) == projectRef);
-}
-
-__attribute__((__pure__))
 static int
 hashInstruction(const MalBlkRecord *mb, const InstrRecord *p)
 {
@@ -67,6 +60,11 @@ OPTcommonTermsImplementation(Client ctx,
        if (isSimpleSQL(mb) || MB_LARGE(mb)) {
                goto wrapup1;
        }
+       for (i = 0; i < mb->stop; i++) {
+               p = mb->stmt[i];
+               if (getFunctionId(p) == replaceRef)
+                       goto wrapup1;
+       }
 
        (void) stk;
        allocator_state ta_state = ma_open(ta);
@@ -193,8 +191,7 @@ OPTcommonTermsImplementation(Client ctx,
                                        && !hasCommonResults(p, q)
                                        && !isUnsafeFunction(q)
                                        && !isUpdateInstruction(q)
-                                       && !isProjectConst(q) &&        /* 
disable project(x,val), as its used for the result of case statements */
-                                       isLinearFlow(q)) {
+                                       && isLinearFlow(q)) {
                                        if (safetyBarrier(p, q)) {
                                                TRC_DEBUG(MAL_OPTIMIZER, 
"Safety barrier reached\n");
                                                break;
diff --git a/sql/test/BugTracker-2025/Tests/7726-commonterms.test 
b/sql/test/BugTracker-2025/Tests/7726-commonterms.test
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2025/Tests/7726-commonterms.test
@@ -0,0 +1,3 @@
+
+statement error
+SELECT ( WITH x AS ( SELECT * FROM generate_series ( 32989 , 8100 ) EXCEPT 
SELECT * FROM generate_series ( 44 , 3 ) ) SELECT DISTINCT ( WITH x AS ( SELECT 
* FROM generate_series ( 32989 , 8100 ) EXCEPT SELECT * FROM generate_series ( 
44 , 3 ) ) SELECT CASE WHEN NULL IN ( 69 , MAX ( CASE WHEN 97 THEN 66 END ) 
OVER ( ) + ( SELECT COUNT ( * ) ) ) THEN 41 WHEN 1 THEN 1 END FROM x ) FROM x ) 
diff --git a/sql/test/BugTracker-2025/Tests/All 
b/sql/test/BugTracker-2025/Tests/All
--- a/sql/test/BugTracker-2025/Tests/All
+++ b/sql/test/BugTracker-2025/Tests/All
@@ -67,6 +67,7 @@ 7719-crash-in-complex-query
 7720-coalesce
 7722-recusive-cte-with-error-crash
 7725-crash-find-rel-ref
+7726-commonterms
 7730-generate-series-month-int
 7732-table-exp-issue
 7734-epoch-missing-cast
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to