Changeset: a8928b444f4c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a8928b444f4c
Modified Files:
        monetdb5/optimizer/opt_pushselect.c
        sql/test/SQLancer/Tests/sqlancer09.sql
        sql/test/SQLancer/Tests/sqlancer09.stable.out
Branch: Oct2020
Log Message:

Likeselect call requires a candidate list, if there's none pass a nil BAT


diffs (103 lines):

diff --git a/monetdb5/optimizer/opt_pushselect.c 
b/monetdb5/optimizer/opt_pushselect.c
--- a/monetdb5/optimizer/opt_pushselect.c
+++ b/monetdb5/optimizer/opt_pushselect.c
@@ -324,20 +324,25 @@ OPTpushselectImplementation(Client cntxt
                                                (q->argc != 4 || 
!isaBatType(getArgType(mb, q, 3))) /* escape is a value */
                                                ) {
                                        InstrPtr r = newInstruction(mb, 
algebraRef, likeselectRef);
-                                       int has_cand = (getArgType(mb, p, 2) == 
newBatType(TYPE_oid));
+                                       int has_cand = (getArgType(mb, p, 2) == 
newBatType(TYPE_oid)), offset = 0;
                                        int a, anti = (getFunctionId(q)[0] == 
'n'), ignore_case = (getFunctionId(q)[anti?4:0] == 'i');
 
                                        getArg(r,0) = getArg(p,0);
                                        r = addArgument(mb, r, getArg(q, 1));
-                                       if (has_cand)
+                                       if (has_cand) {
                                                r = addArgument(mb, r, 
getArg(p, 2));
+                                               offset = 1;
+                                       } else if (isaBatType(getArgType(mb, q, 
1))) { /* likeselect calls have a candidate parameter */
+                                               r = pushNil(mb, r, TYPE_bat);
+                                               offset = 1;
+                                       }
                                        for(a = 2; a<q->argc; a++)
                                                r = addArgument(mb, r, 
getArg(q, a));
-                                       if (r->argc < (4+has_cand))
+                                       if (r->argc < (4+offset))
                                                r = pushStr(mb, r, ""); /* 
default esc */
-                                       if (r->argc < (5+has_cand))
+                                       if (r->argc < (5+offset))
                                                r = pushBit(mb, r, ignore_case);
-                                       if (r->argc < (6+has_cand))
+                                       if (r->argc < (6+offset))
                                                r = pushBit(mb, r, anti);
                                        freeInstruction(p);
                                        p = r;
diff --git a/sql/test/SQLancer/Tests/sqlancer09.sql 
b/sql/test/SQLancer/Tests/sqlancer09.sql
--- a/sql/test/SQLancer/Tests/sqlancer09.sql
+++ b/sql/test/SQLancer/Tests/sqlancer09.sql
@@ -372,3 +372,29 @@ create or replace view v110(vc0) as (val
 
 select 1 from v64, t1, v110 where t1.c0 > v64.vc2;
 ROLLBACK;
+
+START TRANSACTION;
+create or replace view v11(vc0, vc1) as (values (cast(r'<' as string), 
((((356910743)||(324718164)))<<(sql_max(962062904, -1226062612)))),
+(r'e]+)Nik', ((cast(-1267863719 as tinyint))&(- (340796877)))), (case when 
((r'24060')not like(r'f')) then r'vyA,R' else r'68' end,
++ (greatest(113, 0.61746233049203114173764106453745625913143157958984375))));
+
+create or replace view v13(vc0, vc1) as (values 
(((0.9896616954779023)<(greatest(-1982788333, 
0.76584341990855342441335551484371535480022430419921875)))
+, cast(1938193505 as boolean)), (greatest(false, false), cast(cast(r'rHIVNz' 
as int) as boolean))) with check option;
+
+create or replace view v23(vc0, vc1) as (values (case when ((false)and(true)) 
then ((25922)*(697298603)) when not (false) then - (2909) end,
+cast(case r'17841' when r'155' then 2909 when r'116' then 17275 end as int)));
+
+SELECT CAST(SUM(agg0) as BIGINT) FROM (
+       SELECT count(ALL 1) as agg0 FROM v23, v13, v11 CROSS JOIN (VALUES 
(scale_down(CAST(0.31366895126242933 AS BIGINT),
+       NULLIF(0.6018914, 0.947574)), "isauuid"(r''))) AS sub0 WHERE 
((greatest(v11.vc0, v11.vc0))NOT LIKE(CAST(r'' AS STRING(299))))
+       UNION ALL
+       SELECT count(ALL 1) as agg0 FROM v23, v13, v11 CROSS JOIN (VALUES 
(scale_down(CAST(0.31366895126242933 AS BIGINT),
+       NULLIF(0.6018914, 0.947574)), "isauuid"(r''))) AS sub0 WHERE NOT 
(((greatest(v11.vc0, v11.vc0))NOT LIKE(CAST(r'' AS STRING(299)))))
+       UNION ALL
+       SELECT count(ALL 1) as agg0 FROM v23, v13, v11 CROSS JOIN (VALUES 
(scale_down(CAST(0.31366895126242933 AS BIGINT),
+       NULLIF(0.6018914, 0.947574)), "isauuid"(r''))) AS sub0 WHERE 
(((greatest(v11.vc0, v11.vc0))NOT LIKE(CAST(r'' AS STRING(299))))) IS NULL
+       ) as asdf;
+
+create or replace view v11(vc0) as (values ('<'), ('a'));
+SELECT 1 FROM v11 WHERE v11.vc0 LIKE '' IS NULL;
+ROLLBACK;
diff --git a/sql/test/SQLancer/Tests/sqlancer09.stable.out 
b/sql/test/SQLancer/Tests/sqlancer09.stable.out
--- a/sql/test/SQLancer/Tests/sqlancer09.stable.out
+++ b/sql/test/SQLancer/Tests/sqlancer09.stable.out
@@ -360,6 +360,32 @@ stdout of test 'sqlancer09` in directory
 [ 1    ]
 [ 1    ]
 #ROLLBACK;
+#START TRANSACTION;
+#create or replace view v11(vc0, vc1) as (values (cast(r'<' as string), 
((((356910743)||(324718164)))<<(sql_max(962062904, -1226062612)))),
+#(r'e]+)Nik', ((cast(-1267863719 as tinyint))&(- (340796877)))), (case when 
((r'24060')not like(r'f')) then r'vyA,R' else r'68' end,
+#+ (greatest(113, 0.61746233049203114173764106453745625913143157958984375))));
+#create or replace view v13(vc0, vc1) as (values 
(((0.9896616954779023)<(greatest(-1982788333, 
0.76584341990855342441335551484371535480022430419921875)))
+#, cast(1938193505 as boolean)), (greatest(false, false), cast(cast(r'rHIVNz' 
as int) as boolean))) with check option;
+#create or replace view v23(vc0, vc1) as (values (case when ((false)and(true)) 
then ((25922)*(697298603)) when not (false) then - (2909) end,
+#cast(case r'17841' when r'155' then 2909 when r'116' then 17275 end as int)));
+#SELECT CAST(SUM(agg0) as BIGINT) FROM (
+#      SELECT count(ALL 1) as agg0 FROM v23, v13, v11 CROSS JOIN (VALUES 
(scale_down(CAST(0.31366895126242933 AS BIGINT),
+#      NULLIF(0.6018914, 0.947574)), "isauuid"(r''))) AS sub0 WHERE 
((greatest(v11.vc0, v11.vc0))NOT LIKE(CAST(r'' AS STRING(299))))
+#      UNION ALL
+#      SELECT count(ALL 1) as agg0 FROM v23, v13, v11 CROSS JOIN (VALUES 
(scale_down(CAST(0.31366895126242933 AS BIGINT),
+#      NULLIF(0.6018914, 0.947574)), "isauuid"(r''))) AS sub0 WHERE NOT 
(((greatest(v11.vc0, v11.vc0))NOT LIKE(CAST(r'' AS STRING(299)))))
+% .%145 # table_name
+% %145 # name
+% bigint # type
+% 2 # length
+[ 12   ]
+#create or replace view v11(vc0) as (values ('<'), ('a'));
+#SELECT 1 FROM v11 WHERE v11.vc0 LIKE '' IS NULL;
+% .%4 # table_name
+% %4 # name
+% tinyint # type
+% 1 # length
+#ROLLBACK;
 
 # 14:35:03 >  
 # 14:35:03 >  "Done."
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to