Changeset: c68566ea1402 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/c68566ea1402
Modified Files:
        sql/test/BugTracker-2025/Tests/All
        testing/sqllogictest.py
Branch: default
Log Message:

Merge with Mar2025 branch.


diffs (260 lines):

diff --git a/sql/test/BugTracker-2025/Tests/7643_select_0_optimizer_bug.test 
b/sql/test/BugTracker-2025/Tests/7643_select_0_optimizer_bug.test
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2025/Tests/7643_select_0_optimizer_bug.test
@@ -0,0 +1,145 @@
+statement ok
+CREATE TABLE sys."table_a" (
+       "col1" varchar,
+       "col2" varchar,
+       "col3" varchar
+)
+
+statement ok
+INSERT INTO sys."table_a" ("col1","col2","col3") VALUES
+        ('68496e8de22d49608a03a72e;INST1;risk;1','INST1','9.9999'),
+        ('68496e8de22d49608a03a72e;INST1;risk;2','INST1','100'),
+        ('68496e8de22d49608a03a72e;INST1;risk;3','INST1','110'),
+        ('68496e8de22d49608a03a72e;INST2;risk;4','INST2','310'),
+        ('68496e8de22d49608a03a72e;INST2;risk;5','INST2','111'),
+        ('68496e8de22d49608a03a72e;INST2;risk;6','INST2','10'),
+        ('68496e8de22d49608a03a72e;INST2;risk;7','INST2','140'),
+        ('68496e8de22d49608a03a72e;INST1;risk;8','INST1','150'),
+        ('68496e8de22d49608a03a72e;INST4;risk;9','INST4','115'),
+        ('68496e8de22d49608a03a72e;INST3;risk;10','INST3','610')
+
+
+statement ok
+CREATE TABLE sys."table_b" (
+       "col1" varchar,
+       "col4" varchar
+)
+
+statement ok
+INSERT INTO sys."table_b" ("col1","col4") VALUES
+        ('68496e8de22d49608a03a72e;INST1;risk;1','AA|BB|20241231|1.1'),
+        ('68496e8de22d49608a03a72e;INST1;risk;2','AA|BC|20241231|1.2'),
+        ('68496e8de22d49608a03a72e;INST1;risk;3','AA|CB|20241231|0.1'),
+        ('68496e8de22d49608a03a72e;INST2;risk;4','CA|BC|20241231|1.1'),
+        ('68496e8de22d49608a03a72e;INST2;risk;5','CA|BV|20241231|1.1'),
+        ('68496e8de22d49608a03a72e;INST2;risk;6','AA|AB|20241231|1.1'),
+        ('68496e8de22d49608a03a72e;INST2;risk;7','AA|CV|20241231|1.1'),
+        ('68496e8de22d49608a03a72e;INST1;risk;8','AA|XX|20241231|1.1'),
+        ('68496e8de22d49608a03a72e;INST4;risk;9','VV|BC|20241231|1.1'),
+        ('68496e8de22d49608a03a72e;INST3;risk;10','DD|VV|20241231|1.1')
+
+-- query without the (select 0) query parts
+query TTT nosort
+SELECT acol1,
+acol2,
+SPLIT_PART(bcol4, '|', 4) as rate
+FROM (
+    SELECT a.col1 as acol1,
+       a.col2 as acol2,
+       a.col3 as acol3,
+       b.col1 as bcol1,
+       b.col4 as bcol4
+    FROM table_a a
+    INNER JOIN table_b b
+       ON a.col1 = b.col1
+       where a.col2 = 'INST1'
+) abc
+order by rate asc
+LIMIT 2 offset 1
+----
+68496e8de22d49608a03a72e;INST1;risk;1
+INST1
+1.1
+68496e8de22d49608a03a72e;INST1;risk;8
+INST1
+1.1
+
+-- query with the added '(select 0)' query parts, fails.
+-- server crash: sql/backends/monet5/rel_bin.c:1858: exp_bin: Assertion `s' 
failed.
+-- Something wrong with the MAL optimizer, run the query with EXPLAIN
+skipif knownfail
+query TTTIIR nosort
+SELECT acol1,
+acol2,
+SPLIT_PART(bcol4, '|', 4) as rate,
+(select 0) as "col5",
+(select 0) as "col6",
+acol3 + (select 0) + ( select 0) as "total"
+FROM (
+    SELECT a.col1 as acol1,
+       a.col2 as acol2,
+       a.col3 as acol3,
+       b.col1 as bcol1,
+       b.col4 as bcol4
+    FROM table_a a
+    INNER JOIN table_b b
+       ON a.col1 = b.col1
+       where a.col2 = 'INST1'
+) abc
+order by rate asc
+LIMIT 2 offset 1
+----
+68496e8de22d49608a03a72e;INST1;risk;1
+INST1
+1.1
+0
+0
+10.000
+68496e8de22d49608a03a72e;INST1;risk;8
+INST1
+1.1
+0
+0
+150.000
+
+-- query without the 'select' in '(select 0)' query parts, works
+query TTTIIR nosort
+SELECT acol1,
+acol2,
+SPLIT_PART(bcol4, '|', 4) as rate,
+(0) as "col5",
+(0) as "col6",
+acol3 + (0) + (0) as "total"
+FROM (
+    SELECT a.col1 as acol1,
+       a.col2 as acol2,
+       a.col3 as acol3,
+       b.col1 as bcol1,
+       b.col4 as bcol4
+    FROM table_a a
+    INNER JOIN table_b b
+       ON a.col1 = b.col1
+       where a.col2 = 'INST1'
+) abc
+order by rate asc
+LIMIT 2 offset 1
+----
+68496e8de22d49608a03a72e;INST1;risk;1
+INST1
+1.1
+0
+0
+10.000
+68496e8de22d49608a03a72e;INST1;risk;8
+INST1
+1.1
+0
+0
+150.000
+
+statement ok
+DROP TABLE sys."table_b"
+
+statement ok
+DROP TABLE sys."table_a"
+
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
@@ -12,6 +12,7 @@ 7633-crash-leftjoin-any
 7634_join_with_subquery_crash
 7635_name_propagation_missing
 7636_antijoin_crash
+7643_select_0_optimizer_bug
 7644_antijoin_crash
 7645_not_likeselect
 7646_leftjoin_crash
diff --git a/testing/Mtest.py.in b/testing/Mtest.py.in
--- a/testing/Mtest.py.in
+++ b/testing/Mtest.py.in
@@ -48,6 +48,7 @@ MonetDB_VERSION = '@MONETDB_VERSION@'.sp
 procdebug = False
 verbosity = 0
 approve = False
+replace = False
 stop_crash = False
 
 initdb = None
@@ -2984,11 +2985,14 @@ def DoIt(env, SERVER, CALL, TST, EXT, Te
                             testfile = TST+EXT
                             if lang == 'sql' and 
os.path.exists(os.path.join(TSTTRGDIR, TST+'.test.in')):
                                 testfile = TST+'.test.in'
+                                
defines.append(f'QTSTDATAPATH={TSTDATAPATH.replace("\\","\\\\")}')
                                 defines.append(f'TSTDATAPATH={TSTDATAPATH}')
-                                defines.append(f'TSTSRCBASE={TSTSRCBASE}')
+                                
defines.append(f'UTSTSRCDIR=file://{url(TSTSRCDIR)}')
+                                
defines.append(f'QTSTSRCDIR={TSTSRCDIR.replace("\\","\\\\")}')
                                 defines.append(f'TSTSRCDIR={TSTSRCDIR}')
+                                
defines.append(f'QTSTTRGDIR={TSTTRGDIR.replace("\\","\\\\")}')
                                 defines.append(f'TSTTRGDIR={TSTTRGDIR}')
-                                
defines.append(f'UTSTSRCDIR=file://{url(TSTSRCDIR)}')
+                                defines.append(f'TSTSRCBASE={TSTSRCBASE}')
                                 defines.append(f'TSTDB={TSTDB}')
                                 defines.append(f'MAPIPORT={pSrvr.port}')
                             try:
@@ -3014,6 +3018,12 @@ def DoIt(env, SERVER, CALL, TST, EXT, Te
                                     returncode = 'error'
                                 elif sql.timedout:
                                     returncode = 'timeout'
+                                if approve and replace and not sql.timedout:
+                                    with openutf8(os.path.join(TSTTRGDIR, 
TST+'.newtest')) as fin, \
+                                         openutf8(os.path.join(TSTSRCDIR, 
testfile + 'new'), 'w') as fout:
+                                        fout.write(fin.read())
+                                        fout.flush()
+                                    os.replace(os.path.join(TSTSRCDIR, 
testfile + 'new'), os.path.join(TSTSRCDIR, testfile))
             elif CALL == 'sql':
                 TSTs = []
                 test = re.compile('^'+TST+EXT+'$', re.MULTILINE)
@@ -3513,6 +3523,7 @@ def main(argv) :
     parser.add_argument('--initdb', action='store', dest='initdb', 
metavar='<zipfile>', help='zip file with contents for initial database')
     parser.add_argument('--single-in-memory', action='store_true', 
dest='single_in_memory', help='use --in-memory for SingleServer directories')
     parser.add_argument('--approve', action='store_true', help='produce 
.newtest file in testing directory with calculated content')
+    parser.add_argument('--approve+replace', action='store_true', 
dest='approve_replace', help='produce .newtest file in testing directory with 
calculated content')
     parser.add_argument('--ignore-conditions', action='store_true', 
dest='ignore_conditions', help='ignore conditions in All file')
     parser.add_argument('--skip-test-with-timeout', action='store_true', 
help='skip tests that have a .timeout file')
     parser.add_argument('--stop-at-crash', action='store_true', 
dest='stop_crash', help='stop testing when the server crashes')
@@ -3548,9 +3559,12 @@ def main(argv) :
     global procdebug
     procdebug = opts.procdebug
     global approve
-    approve = opts.approve
+    global replace
+    approve = opts.approve or opts.approve_replace
     if approve:
         os.environ['MTEST_APPROVE'] = 'TRUE'
+    if opts.approve_replace:
+        replace = True
     global stop_crash
     stop_crash = opts.stop_crash
     global ignore_conditions
diff --git a/testing/sqllogictest.py b/testing/sqllogictest.py
--- a/testing/sqllogictest.py
+++ b/testing/sqllogictest.py
@@ -770,9 +770,7 @@ class SQLLogic:
                 val = val.strip()
                 defs.append((re.compile(r'\$(' + key + r'\b|{' + key + '})'),
                              val, key))
-                defs.append((re.compile(r'\$(Q' + key + r'\b|{Q' + key + '})'),
-                             val.replace('\\', '\\\\'), 'Q'+key))
-        self.defines = sorted(defs, key=lambda x: (-len(x[1]), x[1], x[2]))
+        self.defines = defs
         self.lines = []
 
     def readline(self):
@@ -802,10 +800,10 @@ class SQLLogic:
                     # line = line.replace('\''+val.replace('\\', '\\\\'),
                     #                     '\'${Q'+key+'}')
                     # line = line.replace(val, '${'+key+'}')
+                    if key.startswith('Q') and (("r'"+val) in line or 
("R'"+val) in line):
+                        continue
                     line = line.replace("r'"+val, "r'$"+key)
                     line = line.replace("R'"+val, "R'$"+key)
-                    line = line.replace("'"+val.replace('\\', '\\\\'),
-                                        "'$Q"+key)
                     line = line.replace(val, '$'+key)
             i = 0
             while i < len(self.lines):
@@ -1040,6 +1038,8 @@ class SQLLogic:
                 self.writeline()
             else:
                 self.raise_error(f'unrecognized command {words[0]}')
+        if approve:
+            approve.flush()
 
 if __name__ == '__main__':
     import argparse
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to