Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/cargo/strum-0.26.1
Browse files Browse the repository at this point in the history
  • Loading branch information
TennyZhuang authored Jan 30, 2024
2 parents 0bba146 + 43b6eef commit 99ab861
Show file tree
Hide file tree
Showing 8 changed files with 707 additions and 2 deletions.
242 changes: 242 additions & 0 deletions e2e_test/batch/basic/case_when_optimization.slt.part
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
statement ok
SET RW_IMPLICIT_FLUSH TO true;

statement ok
CREATE TABLE t1 (c1 INT, c2 INT, c3 INT);

statement ok
INSERT INTO t1 VALUES (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5),
(6, 6, 6), (7, 7, 7), (8, 8, 8), (9, 9, 9), (10, 10, 10),
(11, 11, 11), (12, 12, 12), (13, 13, 13), (14, 14, 14), (15, 15, 15),
(16, 16, 16), (17, 17, 17), (18, 18, 18), (19, 19, 19), (20, 20, 20),
(21, 21, 21), (22, 22, 22), (23, 23, 23), (24, 24, 24), (25, 25, 25),
(26, 26, 26), (27, 27, 27), (28, 28, 28), (29, 29, 29), (30, 30, 30),
(31, 31, 31), (32, 32, 32), (33, 33, 33), (34, 34, 34), (35, 35, 35),
(36, 36, 36), (37, 37, 37), (38, 38, 38), (39, 39, 39), (40, 40, 40),
(41, 41, 41), (42, 42, 42), (43, 43, 43), (44, 44, 44), (45, 45, 45),
(46, 46, 46), (47, 47, 47), (48, 48, 48), (49, 49, 49), (50, 50, 50),
(51, 51, 51), (52, 52, 52), (53, 53, 53), (54, 54, 54), (55, 55, 55),
(56, 56, 56), (57, 57, 57), (58, 58, 58), (59, 59, 59), (60, 60, 60),
(61, 61, 61), (62, 62, 62), (63, 63, 63), (64, 64, 64), (65, 65, 65),
(66, 66, 66), (67, 67, 67), (68, 68, 68), (69, 69, 69), (70, 70, 70),
(71, 71, 71), (72, 72, 72), (73, 73, 73), (74, 74, 74), (75, 75, 75),
(76, 76, 76), (77, 77, 77), (78, 78, 78), (79, 79, 79), (80, 80, 80),
(81, 81, 81), (82, 82, 82), (83, 83, 83), (84, 84, 84), (85, 85, 85),
(86, 86, 86), (87, 87, 87), (88, 88, 88), (89, 89, 89), (90, 90, 90),
(91, 91, 91), (92, 92, 92), (93, 93, 93), (94, 94, 94), (95, 95, 95),
(96, 96, 96), (97, 97, 97), (98, 98, 98), (99, 99, 99), (100, 100, 100);


# 101 arms case-when expression, with optimizable pattern
query I
SELECT
CASE c1
WHEN 1 THEN 'one'
WHEN 2 THEN 'two'
WHEN 3 THEN 'three'
WHEN 4 THEN 'four'
WHEN 5 THEN 'five'
WHEN 6 THEN 'six'
WHEN 7 THEN 'seven'
WHEN 8 THEN 'eight'
WHEN 9 THEN 'nine'
WHEN 10 THEN 'ten'
WHEN 11 THEN 'eleven'
WHEN 12 THEN 'twelve'
WHEN 13 THEN 'thirteen'
WHEN 14 THEN 'fourteen'
WHEN 15 THEN 'fifteen'
WHEN 16 THEN 'sixteen'
WHEN 17 THEN 'seventeen'
WHEN 18 THEN 'eighteen'
WHEN 19 THEN 'nineteen'
WHEN 20 THEN 'twenty'
WHEN 21 THEN 'twenty-one'
WHEN 22 THEN 'twenty-two'
WHEN 23 THEN 'twenty-three'
WHEN 24 THEN 'twenty-four'
WHEN 25 THEN 'twenty-five'
WHEN 26 THEN 'twenty-six'
WHEN 27 THEN 'twenty-seven'
WHEN 28 THEN 'twenty-eight'
WHEN 29 THEN 'twenty-nine'
WHEN 30 THEN 'thirty'
WHEN 31 THEN 'thirty-one'
WHEN 32 THEN 'thirty-two'
WHEN 33 THEN 'thirty-three'
WHEN 34 THEN 'thirty-four'
WHEN 35 THEN 'thirty-five'
WHEN 36 THEN 'thirty-six'
WHEN 37 THEN 'thirty-seven'
WHEN 38 THEN 'thirty-eight'
WHEN 39 THEN 'thirty-nine'
WHEN 40 THEN 'forty'
WHEN 41 THEN 'forty-one'
WHEN 42 THEN 'forty-two'
WHEN 43 THEN 'forty-three'
WHEN 44 THEN 'forty-four'
WHEN 45 THEN 'forty-five'
WHEN 46 THEN 'forty-six'
WHEN 47 THEN 'forty-seven'
WHEN 48 THEN 'forty-eight'
WHEN 49 THEN 'forty-nine'
WHEN 50 THEN 'fifty'
WHEN 51 THEN 'fifty-one'
WHEN 52 THEN 'fifty-two'
WHEN 53 THEN 'fifty-three'
WHEN 54 THEN 'fifty-four'
WHEN 55 THEN 'fifty-five'
WHEN 56 THEN 'fifty-six'
WHEN 57 THEN 'fifty-seven'
WHEN 58 THEN 'fifty-eight'
WHEN 59 THEN 'fifty-nine'
WHEN 60 THEN 'sixty'
WHEN 61 THEN 'sixty-one'
WHEN 62 THEN 'sixty-two'
WHEN 63 THEN 'sixty-three'
WHEN 64 THEN 'sixty-four'
WHEN 65 THEN 'sixty-five'
WHEN 66 THEN 'sixty-six'
WHEN 67 THEN 'sixty-seven'
WHEN 68 THEN 'sixty-eight'
WHEN 69 THEN 'sixty-nine'
WHEN 70 THEN 'seventy'
WHEN 71 THEN 'seventy-one'
WHEN 72 THEN 'seventy-two'
WHEN 73 THEN 'seventy-three'
WHEN 74 THEN 'seventy-four'
WHEN 75 THEN 'seventy-five'
WHEN 76 THEN 'seventy-six'
WHEN 77 THEN 'seventy-seven'
WHEN 78 THEN 'seventy-eight'
WHEN 79 THEN 'seventy-nine'
WHEN 80 THEN 'eighty'
WHEN 81 THEN 'eighty-one'
WHEN 82 THEN 'eighty-two'
WHEN 83 THEN 'eighty-three'
WHEN 84 THEN 'eighty-four'
WHEN 85 THEN 'eighty-five'
WHEN 86 THEN 'eighty-six'
WHEN 87 THEN 'eighty-seven'
WHEN 88 THEN 'eighty-eight'
WHEN 89 THEN 'eighty-nine'
WHEN 90 THEN 'ninety'
WHEN 91 THEN 'ninety-one'
WHEN 92 THEN 'ninety-two'
WHEN 93 THEN 'ninety-three'
WHEN 94 THEN 'ninety-four'
WHEN 95 THEN 'ninety-five'
WHEN 96 THEN 'ninety-six'
WHEN 97 THEN 'ninety-seven'
WHEN 98 THEN 'ninety-eight'
WHEN 99 THEN 'ninety-nine'
WHEN 100 THEN 'one hundred'
ELSE
'114514'
END
FROM t1
ORDER BY c1 ASC;
----
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
fifteen
sixteen
seventeen
eighteen
nineteen
twenty
twenty-one
twenty-two
twenty-three
twenty-four
twenty-five
twenty-six
twenty-seven
twenty-eight
twenty-nine
thirty
thirty-one
thirty-two
thirty-three
thirty-four
thirty-five
thirty-six
thirty-seven
thirty-eight
thirty-nine
forty
forty-one
forty-two
forty-three
forty-four
forty-five
forty-six
forty-seven
forty-eight
forty-nine
fifty
fifty-one
fifty-two
fifty-three
fifty-four
fifty-five
fifty-six
fifty-seven
fifty-eight
fifty-nine
sixty
sixty-one
sixty-two
sixty-three
sixty-four
sixty-five
sixty-six
sixty-seven
sixty-eight
sixty-nine
seventy
seventy-one
seventy-two
seventy-three
seventy-four
seventy-five
seventy-six
seventy-seven
seventy-eight
seventy-nine
eighty
eighty-one
eighty-two
eighty-three
eighty-four
eighty-five
eighty-six
eighty-seven
eighty-eight
eighty-nine
ninety
ninety-one
ninety-two
ninety-three
ninety-four
ninety-five
ninety-six
ninety-seven
ninety-eight
ninety-nine
one hundred

statement ok
drop table t1;
3 changes: 3 additions & 0 deletions proto/expr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ message ExprNode {
LTRIM = 210;
RTRIM = 211;
CASE = 212;
// Optimize case-when expression to constant lookup
// when arms are in a large scale with simple form
CONSTANT_LOOKUP = 624;
// ROUND(numeric, integer) -> numeric
ROUND_DIGIT = 213;
// ROUND(numeric) -> numeric
Expand Down
Loading

0 comments on commit 99ab861

Please sign in to comment.