Files
tidb/planner/core/testdata/integration_suite_in.json
guo-shaoge 9b9a300485 expression: support lpad/rpad pushdown to tiflash (#31099)
* expression: support lpad/rpad pushdown to tiflash

Signed-off-by: guo-shaoge <shaoge1994@163.com>
2021-12-30 23:33:34 +08:00

424 lines
20 KiB
JSON

[
{
"name": "TestPushLimitDownIndexLookUpReader",
"cases": [
// Limit should be pushed down into IndexLookUpReader, row count of IndexLookUpReader and TableScan should be 1.00.
"explain format = 'brief' select * from tbl use index(idx_b_c) where b > 1 limit 2,1",
// Projection atop IndexLookUpReader, Limit should be pushed down into IndexLookUpReader, and Projection should have row count 1.00 as well.
"explain format = 'brief' select * from tbl use index(idx_b_c) where b > 1 order by b desc limit 2,1",
// Limit should be pushed down into IndexLookUpReader when Selection on top of IndexScan.
"explain format = 'brief' select * from tbl use index(idx_b_c) where b > 1 and c > 1 limit 2,1",
// Limit should NOT be pushed down into IndexLookUpReader when Selection on top of TableScan.
"explain format = 'brief' select * from tbl use index(idx_b_c) where b > 1 and a > 1 limit 2,1"
]
},
{
"name": "TestIsFromUnixtimeNullRejective",
"cases": [
// fix #12385
"explain format = 'brief' select * from t t1 left join t t2 on t1.a=t2.a where from_unixtime(t2.b);"
]
},
{
"name": "TestAggColumnPrune",
"cases": [
"select count(1) from t join (select count(1) from t where false) as tmp",
"select count(1) from t join (select max(a) from t where false) as tmp",
"select count(1) from t join (select min(a) from t where false) as tmp",
"select count(1) from t join (select sum(a) from t where false) as tmp",
"select count(1) from t join (select avg(a) from t where false) as tmp",
"select count(1) from t join (select count(1) from t where false group by a) as tmp",
"select count(1) from t join (select max(a) from t where false group by a) as tmp",
"select count(1) from t join (select min(a) from t where false group by a) as tmp",
"select count(1) from t join (select sum(a) from t where false group by a) as tmp",
"select count(1) from t join (select avg(a) from t where false group by a) as tmp",
"SELECT avg(2) FROM(SELECT min(c) FROM t JOIN(SELECT 1 c) d ORDER BY a) e"
]
},
{
"name": "TestIndexJoinInnerIndexNDV",
"cases": [
// t2 should use idx2 instead of idx1, since idx2 has larger NDV.
"explain format = 'brief' select /*+ inl_join(t2) */ * from t1, t2 where t1.a = t2.a and t1.b = t2.b and t1.c = t2.c"
]
},
{
"name": "TestSimplifyOuterJoinWithCast",
"cases": [
// LeftOuterJoin should no be simplified to InnerJoin.
"explain format = 'brief' select * from t t1 left join t t2 on t1.a = t2.a where cast(t1.b as date) >= '2019-01-01'"
]
},
{
"name": "TestMaxMinEliminate",
"cases": [
"explain format = 'brief' (select max(a) from t) union (select min(a) from t)",
"explain format = 'brief' select min(a), max(a) from cluster_index_t",
"explain format = 'brief' select min(b), max(b) from cluster_index_t where a = 1",
"explain format = 'brief' select min(a), max(a) from cluster_index_t where b = 1",
"explain format = 'brief' select min(b), max(b) from cluster_index_t where b = 1"
]
},
{
"name": "TestIndexJoinUniqueCompositeIndex",
"cases": [
// Row count of IndexScan should be 2.
"explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from t1 join t2 on t1.a = t2.a and t1.c = t2.c",
// Row count of IndexScan should be 2.
"explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from t1 join t2 on t1.a = t2.a and t1.c <= t2.b",
// Row count of IndexScan should be 1.
"explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from t1 join t2 on t1.a = t2.a and t2.b = 1"
]
},
{
"name": "TestPartitionTableStats",
"cases": [
"explain format = 'brief' select * from t order by a",
"select * from t order by a",
"explain format = 'brief' select * from t order by a limit 3",
"select * from t order by a limit 3"
]
},
{
"name": "TestIndexMerge",
"cases": [
"explain format = 'brief' select /*+ USE_INDEX_MERGE(t, a, b) */ * from t where a = 1 or b = 2",
"explain format = 'brief' select /*+ USE_INDEX_MERGE(t, primary) */ * from t where 1 or t.c",
"explain format = 'brief' select /*+ USE_INDEX_MERGE(t, a, b, c) */ * from t where 1 or t.a = 1 or t.b = 2"
]
},
{
"name": "TestIndexMergeHint4CNF",
"cases": [
"explain format = 'brief' select * from t where b = 1 and (a = 1 or c = 1)",
"explain format = 'brief' select /*+ USE_INDEX_MERGE(t, a, c) */ * from t where b = 1 and (a = 1 or c = 1)"
]
},
{
"name": "TestSubqueryWithTopN",
"cases": [
"desc format = 'brief' select t1.b from t t1 where t1.b in (select t2.a from t t2 order by t1.a+t2.a limit 1)",
"desc format = 'brief' select t1.a from t t1 order by (t1.b = 1 and exists (select 1 from t t2 where t1.b = t2.b)) limit 1",
"desc format = 'brief' select * from (select b+b as x from t) t1, t t2 where t1.x=t2.b order by t1.x limit 1"
]
},
{
"name": "TestIndexJoinTableRange",
"cases": [
"desc format = 'brief' select /*+ TIDB_INLJ(t2)*/ * from t1, t2 where t1.a = t2.a and t1.b = t2.b",
"desc format = 'brief' select /*+ TIDB_INLJ(t2)*/ * from t1, t2 where t1.a = t2.a and t1.b = t2.a and t1.b = t2.b"
]
},
{
"name": "TestHintWithRequiredProperty",
"cases": [
"desc format = 'brief' select /*+ INL_JOIN(t2) */ * from t t1, t t2 where t1.a = t2.b order by t2.a",
"desc format = 'brief' select /*+ INL_HASH_JOIN(t2) */ * from t t1, t t2 where t1.a = t2.b order by t2.a",
"desc format = 'brief' select /*+ INL_MERGE_JOIN(t2)*/ t1.a, t2.a from t t1, t t2 ,t t3 where t1.a = t2.a and t3.a=t2.a",
"desc format = 'brief' select * from t t1, (select /*+ HASH_AGG() */ b, max(a) from t t2 group by b) t2 where t1.b = t2.b order by t1.b",
"desc format = 'brief' select /*+ INL_HASH_JOIN(t2) */ distinct t2.a from t t1 join t t2 on t1.a = t2.a",
// This hint cannot work, so choose another plan.
"desc format = 'brief' select /*+ INL_JOIN(t2) */ * from t t1, t t2 where t1.a = t2.c order by t1.a"
]
},
{
"name": "TestIndexHintWarning",
"cases": [
"select /*+ USE_INDEX(t1, j) */ * from t1",
"select /*+ IGNORE_INDEX(t1, j) */ * from t1",
"select /*+ USE_INDEX(t2, a, b, c) */ * from t1",
"select /*+ USE_INDEX(t2) */ * from t1",
"select /*+ USE_INDEX(t1, a), USE_INDEX(t2, a), USE_INDEX(t3, a) */ * from t1, t2 where t1.a=t2.a",
"select /*+ USE_INDEX(t3, a), USE_INDEX(t4, b), IGNORE_INDEX(t3, a) */ * from t1, t2 where t1.a=t2.a",
"select /*+ USE_INDEX_MERGE(t3, a, b, d) */ * from t1",
"select /*+ USE_INDEX_MERGE(t1, a, b, c, d) */ * from t1",
"select /*+ USE_INDEX_MERGE(t1, a, b), USE_INDEX(t1, a) */ * from t1",
"select /*+ USE_INDEX_MERGE(t1, a, b), IGNORE_INDEX(t1, a) */ * from t1",
"select /*+ USE_INDEX_MERGE(t1, primary, a, b, c) */ * from t1"
]
},
{
"name": "TestHintWithoutTableWarning",
"cases": [
"select /*+ TIDB_SMJ() */ * from t1, t2 where t1.a=t2.a",
"select /*+ MERGE_JOIN() */ * from t1, t2 where t1.a=t2.a",
"select /*+ INL_JOIN() */ * from t1, t2 where t1.a=t2.a",
"select /*+ TIDB_INLJ() */ * from t1, t2 where t1.a=t2.a",
"select /*+ INL_HASH_JOIN() */ * from t1, t2 where t1.a=t2.a",
"select /*+ INL_MERGE_JOIN() */ * from t1, t2 where t1.a=t2.a",
"select /*+ HASH_JOIN() */ * from t1, t2 where t1.a=t2.a",
"select /*+ USE_INDEX() */ * from t1, t2 where t1.a=t2.a",
"select /*+ IGNORE_INDEX() */ * from t1, t2 where t1.a=t2.a",
"select /*+ USE_INDEX_MERGE() */ * from t1, t2 where t1.a=t2.a"
]
},
{
"name": "TestPartitionPruningForInExpr",
"cases": [
"explain format = 'brief' select * from t where a in (1, 2,'11')",
"explain format = 'brief' select * from t where a in (17, null)",
"explain format = 'brief' select * from t where a in (16, 'abc')",
"explain format = 'brief' select * from t where a in (15, 0.12, 3.47)",
"explain format = 'brief' select * from t where a in (0.12, 3.47)",
"explain format = 'brief' select * from t where a in (14, floor(3.47))",
"explain format = 'brief' select * from t where b in (3, 4)"
]
},
{
"name": "TestStreamAggProp",
"cases": [
"select /*+ stream_agg() */ count(*) c from t group by a order by c limit 1",
"select /*+ stream_agg() */ count(*) c from t group by a order by c",
"select /*+ stream_agg() */ count(*) c from t group by a order by a limit 1",
"select /*+ stream_agg() */ count(*) c from t group by a order by a"
]
},
{
"name": "TestOptimizeHintOnPartitionTable",
"cases": [
"select /*+ use_index(t) */ * from t",
"select /*+ use_index(t partition(p0, p1) b, c) */ * from t partition(p1,p2)",
"select /*+ use_index(t partition(p_non_exist)) */ * from t partition(p1,p2)",
"select /*+ use_index(t partition(p0, p1) b, c) */ * from t",
"select /*+ ignore_index(t partition(p0, p1) b, c) */ * from t",
"select /*+ hash_join(t1, t2 partition(p0)) */ * from t t1 join t t2 on t1.a = t2.a",
"select /*+ use_index_merge(t partition(p0)) */ * from t where t.b = 1 or t.c = \"8\"",
"select /*+ use_index_merge(t partition(p0, p1) primary, b) */ * from t where t.a = 1 or t.b = 2",
"select /*+ use_index(t partition(p0) b) */ * from t partition(p0, p1)"
]
},
{
"name": "TestAccessPathOnClusterIndex",
"cases": [
"select * from t1",
"select * from t1 where t1.a >= 1 and t1.a < 4",
"select * from t1 where t1.a = 1 and t1.b < \"333\"",
"select t1.a, t1.b, t1.c from t1 where t1.c = 3.3",
"select t1.b, t1.c from t1 where t1.c = 2.2",
"select /*+ use_index(t1, c) */ * from t1",
"select * from t1 use index(c) where t1.c in (2.2, 3.3)",
"select * from t1 where t1.a = 1 order by b",
"select * from t1 order by a, b limit 1",
"select /*+ use_index_merge(t1 primary, c) */ * from t1 where t1.a >= 1 or t1.c = 2.2",
"select /*+ use_index_merge(t1 primary, c) */ * from t1 where t1.a = 1 and t1.b = '111' or t1.c = 3.3"
]
},
{
"name": "TestIndexJoinOnClusteredIndex",
"cases": [
"select /*+ inl_join(t1, t2) */ * from t t1 join t t2 on t1.a = t2.a",
"select /*+ inl_merge_join(t1, t2) */ * from t t1 join t t2 on t1.a = t2.a",
"select /*+ inl_hash_join(t1, t2) */ * from t t1 join t t2 on t1.a = t2.a",
"select /*+ inl_join(t1, t2) */ * from t t1 join t t2 on t1.a = t2.a and t1.b = t2.b",
"select /*+ inl_join(t1, t2) */ * from t t1 join t t2 on t1.c = t2.c",
"select /*+ inl_merge_join(t1,t2) */ t2.a, t2.c, t2.d from t t1 left join t t2 on t1.a = t2.c;"
]
},
{
"name": "TestPartitionExplain",
"cases": [
// Table reader
"select * from pt where c > 10",
"select * from pt where c > 8",
"select * from pt where c < 2 or c >= 9",
// Index reader
"select c from pt",
"select c from pt where c > 10",
"select c from pt where c > 8",
"select c from pt where c < 2 or c >= 9",
// Index Lookup
"select /*+ use_index(pt, i_id) */ * from pt",
"select /*+ use_index(pt, i_id) */ * from pt where id < 4 and c > 10",
"select /*+ use_index(pt, i_id) */ * from pt where id < 10 and c > 8",
"select /*+ use_index(pt, i_id) */ * from pt where id < 10 and c < 2 or c >= 9",
// Partition selection
"select * from pt partition (p0) where c > 8",
"select c from pt partition (p0, p2) where c > 8",
"select /*+ use_index(pt, i_id) */ * from pt partition (p1, p2) where c < 3 and id = 5",
// Index Merge
"select * from pt where id = 4 or c < 7",
"select * from pt where id > 4 or c = 7"
]
},
{
"name": "TestInvalidHint",
"cases": [
"explain format = 'brief' select /*+ use_index_merge(tt) */ * from tt where a=10 or a=20;",
"explain format = 'brief' select /*+ use_index_merge(tt) */ * from tt where a=15 or (a < 10 or a > 20);"
]
},
{
"name": "TestApproxPercentile",
"cases": [
"select approx_percentile(a, 50) from t",
"select approx_percentile(a, 10) from t",
"select approx_percentile(a, 10+70) from t",
"select approx_percentile(a, 10*10) from t",
"select approx_percentile(a, 50) from t group by b order by b"
]
},
{
"name": "TestConvertRangeToPoint",
"cases": [
"explain format = 'brief' select * from t0 where a > 1 and a < 3 order by b limit 2",
"explain format = 'brief' select * from t1 where a >= 2 and a <= 2 and b = 2 and c > 2",
"explain format = 'brief' select * from t2 where a >= 2.5 and a <= 2.5 order by b limit 2",
"explain format = 'brief' select * from t3 where a >= 'a' and a <= 'a' and b = 'b' and c > 'c'"
]
},
{
"name": "TestIssue22105",
"cases": [
"explain format = 'brief' SELECT /*+ use_index_merge(t1)*/ COUNT(*) FROM t1 WHERE (key4=42 AND key6 IS NOT NULL) OR (key1=4 AND key3=6)"
]
},
{
"name": "TestReorderSimplifiedOuterJoins",
"cases": [
// Query with INNER JOIN or LEFT JOIN should have the same plan.
"explain format = 'brief' SELECT t1.pk FROM t1 INNER JOIN t2 ON t1.col1 = t2.pk INNER JOIN t3 ON t1.col3 = t3.pk WHERE t2.col1 IN ('a' , 'b') AND t3.keycol = 'c' AND t1.col2 = 'a' AND t1.col1 != 'abcdef' AND t1.col1 != 'aaaaaa'",
"explain format = 'brief' SELECT t1.pk FROM t1 LEFT JOIN t2 ON t1.col1 = t2.pk LEFT JOIN t3 ON t1.col3 = t3.pk WHERE t2.col1 IN ('a' , 'b') AND t3.keycol = 'c' AND t1.col2 = 'a' AND t1.col1 != 'abcdef' AND t1.col1 != 'aaaaaa'"
]
},
{
"name": "TestDecorrelateInnerJoinInSubquery",
"cases": [
// Query with WHERE or ON should have the same plan, i.e, the Apply has been decorrelated.
"explain format = 'brief' select * from t where exists (select 1 from t t1 join t t2 where t1.a = t2.a and t1.a = t.a)",
"explain format = 'brief' select * from t where exists (select 1 from t t1 join t t2 on t1.a = t2.a and t1.a = t.a)"
]
},
{
"name": "TestMultiColMaxOneRow",
"cases": [
"select (select c from t2 where t2.a = t1.a and t2.b = 1) from t1",
"select (select c from t2 where t2.a = t1.a and (t2.b = 1 or t2.b = 2)) from t1"
]
},
{
"name": "TestIssue24095",
"cases": [
"select count(*) from t join (select t.id, t.value v1 from t join t t1 on t.id = t1.id order by t.value limit 1) v on v.id = t.id and v.v1 = t.value;"
]
},
{
"name": "TestSequenceAsDataSource",
"cases": [
"select 1 from s1",
"select count(1) from s1",
"select count(*) from s1",
"select sum(1) from s1",
"select count(1) as cnt from s1 union select count(1) as cnt from s2"
]
},
{
"name": "TestIsMatchProp",
"cases": [
"select a, b, c from t1 where a > 3 and b = 4 order by a, c",
"select * from t2 where a = 1 and c = 2 order by b, d",
"select a, b, c from t1 where (a = 1 and b = 1 and c = 1) or (a = 1 and b = 1 and c = 2) order by c",
"select a, b, c from t1 where (a = 1 and b = 1 and c < 3) or (a = 1 and b = 1 and c > 6) order by c",
"select * from t2 where ((a = 1 and b = 1 and d < 3) or (a = 1 and b = 1 and d > 6)) and c = 3 order by d"
]
},
{
"name": "TestHeuristicIndexSelection",
"cases": [
"select * from t1 where a = 3 or a = 5",
"select f, g from t1 where f = 2 and g in (3, 4, 5)",
"select * from t1 where c = 1 and (d = 2 or d = 3) and e in (4, 5)",
"select f, g from t1 where f = 2 and g > 3",
"select a, b, c from t2 where a = 1 and b = 2 and c in (1, 2, 3, 4, 5)",
"select * from t3 where (a = 1 or a = 3) and b = 'xx'",
"select * from t4 where (a = 1 or a = 3) and b = 'xx'",
"select a, b from t3 where (a = 1 or a = 3) and b = 'xx'",
"select a, b from t4 where (a = 1 or a = 3) and b = 'xx'",
"update t1 set b = 2 where a = 4 or a = 6",
"delete from t1 where f = 2 and g in (3, 4)",
"insert into t3 select a, b, c from t1 where f = 2",
"replace into t3 select a, b, c from t1 where a = 3"
]
},
{
"name": "TestOutputSkylinePruningInfo",
"cases": [
"select * from t where a > 1 order by f",
"select * from t where f > 1",
"select f from t where f > 1",
"select * from t where f > 3 and g = 5",
"select * from t where g = 5 order by f",
"select * from t where d = 3 order by c, e"
]
},
{
"name": "TestPreferRangeScanForUnsignedIntHandle",
"cases": [
"set tidb_opt_prefer_range_scan = 0",
"explain format = 'verbose' select * from t where b > 5",
"explain format = 'verbose' select * from t where b = 6 order by a limit 1",
"explain format = 'verbose' select * from t where b = 6 limit 1",
"set tidb_opt_prefer_range_scan = 1",
"explain format = 'verbose' select * from t where b > 5",
"explain format = 'verbose' select * from t where b = 6 order by a limit 1",
"explain format = 'verbose' select * from t where b = 6 limit 1"
]
},
{
"name": "TestIssue27083",
"cases": [
"select * from t use index (idx_b) where b = 2 limit 1"
]
},
{
"name": "TestGroupBySetVar",
"cases": [
"select floor(dt.rn/2) rownum, count(c1) from (select @rownum := @rownum + 1 rn, c1 from (select @rownum := -1) drn, t1) dt group by floor(dt.rn/2) order by rownum;",
// TODO: fix these two cases
"select @n:=@n+1 as e from ta group by e",
"select @n:=@n+a as e from ta group by e",
"select * from (select @n:=@n+1 as e from ta) tt group by e",
"select * from (select @n:=@n+a as e from ta) tt group by e",
"select a from ta group by @n:=@n+1",
"select a from ta group by @n:=@n+a"
]
},
{
"name": "TestIssue30200",
"cases": [
// to_base64 and from_base64 has not been pushed to TiKV or TiFlash.
// We expect a Selection will be added above IndexMerge.
"select /*+ use_index_merge(t1) */ 1 from t1 where c1 = 'de' or c2 = '10' and from_base64(to_base64(c1)) = 'ab';",
// `left` has not been pushed to TiKV, but it has been pushed to TiFlash.
// We expect a Selection will be added above IndexMerge.
"select /*+ use_index_merge(t1) */ 1 from t1 where c1 = 'ab' or c2 = '10' and char_length(left(c1, 10)) = 10;",
// c3 is part of idx_1, so it will be put in partial_path's IndexFilters instead of TableFilters.
// But it still cannot be pushed to TiKV. This case cover code in DataSource.buildIndexMergeOrPath.
"select /*+ use_index_merge(tt1) */ 1 from tt1 where c1 = 'de' or c2 = '10' and from_base64(to_base64(c3)) = '10';",
// to_base64(left(pk, 5)) is in partial_path's TableFilters. But it cannot be pushed to TiKV.
// So it should be executed in TiDB. This case cover code in DataSource.buildIndexMergeOrPath.
"select /*+ use_index_merge( tt2 ) */ 1 from tt2 where tt2.c1 in (-3896405) or tt2.pk in (1, 53330) and to_base64(left(pk, 5));",
// This case covert expression index.
"select /*+ use_index_merge(tt3) */ 1 from tt3 where c1 < -10 or c2 < 10 and reverse(c3) = '2';",
// If no hint, we cannot use index merge if filter cannot be pushed to any storage.
"select 1 from t1 where c1 = 'de' or c2 = '10' and from_base64(to_base64(c1)) = 'ab';"
]
},
{
"name": "TestIndexMergeWithCorrelatedColumns",
"cases": [
"select * from t2 where c1 < all(select /*+ use_index_merge(t1) */ c1 from t1 where (c1 = 10 and c1 = t2.c3 or c2 = 1 and c2 = t2.c3) and substring(c3, 10)) order by c1;",
"select * from t2 where c1 < all(select /*+ use_index_merge(t1) */ c1 from t1 where (c1 = 10 and c1 = t2.c3 or c2 = 1 and c2 = t2.c3) and reverse(c3)) order by c1;",
"select * from t2 where c1 < all(select /*+ use_index_merge(t1) */ c1 from t1 where (c1 >= 10 and c1 = t2.c3 or c2 = 1 and c2 = t2.c3) and substring(c3, 10)) order by c1;",
// Test correlated column in IndexPath.TableFilters.
"select c_int from tt1 where c_decimal < all (select /*+ use_index_merge(tt2) */ c_decimal from tt2 where tt1.c_int = tt2.c_int and tt1.c_datetime > tt2.c_datetime and tt2.c_decimal = 9.060 or tt2.c_str <= 'interesting shtern' and tt1.c_int = tt2.c_int) order by 1;",
// Test correlated column in TablePath.TableFilters.
"select c_int from tt1 where c_decimal > all (select /*+ use_index_merge(tt2) */ c_decimal from tt2 where tt2.c_int = 7 and tt2.c_int < tt1.c_decimal or tt2.c_str >= 'zzzzzzzzzzzzzzzzzzz' and tt1.c_int = tt2.c_int) order by 1;"
]
}
]