fix canonicalizer bug

This commit is contained in:
akaError
2023-04-11 12:28:09 +08:00
committed by ob-robot
parent 5d96ca2ba3
commit 4eaf9b58b0
3 changed files with 1141 additions and 525 deletions

View File

@ -6510,20 +6510,6 @@ int ObRawExprUtils::check_need_bool_expr(const ObRawExpr *expr, bool &need_bool_
case T_OP_NOT_IN: case T_OP_NOT_IN:
case T_OP_EXISTS: case T_OP_EXISTS:
case T_OP_NOT_EXISTS: case T_OP_NOT_EXISTS:
// all int is 8 byte in datum, so safe for expr to use get_int() for tinyint type
case T_TINYINT:
case T_SMALLINT:
case T_MEDIUMINT:
case T_INT32:
case T_INT:
case T_UTINYINT:
case T_USMALLINT:
case T_UMEDIUMINT:
case T_UINT32:
case T_UINT64:
case T_OP_XOR: case T_OP_XOR:
case T_OP_BOOL: { case T_OP_BOOL: {
need_bool_expr = false; need_bool_expr = false;

View File

@ -1082,160 +1082,7 @@ not a between 1 and 100
], ],
"children": [ "children": [
{ {
"item_type":"T_INT", "item_type":"T_OP_BOOL",
"result_type": {
"meta": {
"type":"BIGINT",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":1,
"precision":1,
"scale":0
},
"flag":1,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST",
"CNT_CONST"
],
"rel_id": [
],
"value": {
"BIGINT":1
}
},
{
"item_type":"T_INT",
"result_type": {
"meta": {
"type":"BIGINT",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":1,
"precision":1,
"scale":0
},
"flag":1,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST",
"CNT_CONST"
],
"rel_id": [
],
"value": {
"BIGINT":2
}
},
{
"item_type":"T_INT",
"result_type": {
"meta": {
"type":"BIGINT",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":1,
"precision":1,
"scale":0
},
"flag":1,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST",
"CNT_CONST"
],
"rel_id": [
],
"value": {
"BIGINT":3
}
},
{
"item_type":"T_INT",
"result_type": {
"meta": {
"type":"BIGINT",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":1,
"precision":1,
"scale":0
},
"flag":1,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST",
"CNT_CONST"
],
"rel_id": [
],
"value": {
"BIGINT":4
}
},
{
"item_type":"T_INT",
"result_type": {
"meta": {
"type":"BIGINT",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":1,
"precision":1,
"scale":0
},
"flag":1,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST",
"CNT_CONST"
],
"rel_id": [
],
"value": {
"BIGINT":5
}
}
]
}
(1 or 2) or (3 or 4 or 5)
{
"item_type":"T_OP_OR",
"result_type": { "result_type": {
"meta": { "meta": {
"type":"", "type":"",
@ -1256,7 +1103,8 @@ not a between 1 and 100
}, },
"expr_info": [ "expr_info": [
"IS_CONST_EXPR", "IS_CONST_EXPR",
"CNT_CONST" "CNT_CONST",
"IS_INNER_ADDED_EXPR"
], ],
"rel_id": [ "rel_id": [
], ],
@ -1290,7 +1138,37 @@ not a between 1 and 100
"value": { "value": {
"BIGINT":1 "BIGINT":1
} }
}
]
}, },
{
"item_type":"T_OP_BOOL",
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST_EXPR",
"CNT_CONST",
"IS_INNER_ADDED_EXPR"
],
"rel_id": [
],
"children": [
{ {
"item_type":"T_INT", "item_type":"T_INT",
"result_type": { "result_type": {
@ -1320,7 +1198,37 @@ not a between 1 and 100
"value": { "value": {
"BIGINT":2 "BIGINT":2
} }
}
]
}, },
{
"item_type":"T_OP_BOOL",
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST_EXPR",
"CNT_CONST",
"IS_INNER_ADDED_EXPR"
],
"rel_id": [
],
"children": [
{ {
"item_type":"T_INT", "item_type":"T_INT",
"result_type": { "result_type": {
@ -1350,7 +1258,37 @@ not a between 1 and 100
"value": { "value": {
"BIGINT":3 "BIGINT":3
} }
}
]
}, },
{
"item_type":"T_OP_BOOL",
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST_EXPR",
"CNT_CONST",
"IS_INNER_ADDED_EXPR"
],
"rel_id": [
],
"children": [
{ {
"item_type":"T_INT", "item_type":"T_INT",
"result_type": { "result_type": {
@ -1380,7 +1318,37 @@ not a between 1 and 100
"value": { "value": {
"BIGINT":4 "BIGINT":4
} }
}
]
}, },
{
"item_type":"T_OP_BOOL",
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST_EXPR",
"CNT_CONST",
"IS_INNER_ADDED_EXPR"
],
"rel_id": [
],
"children": [
{ {
"item_type":"T_INT", "item_type":"T_INT",
"result_type": { "result_type": {
@ -1413,6 +1381,338 @@ not a between 1 and 100
} }
] ]
} }
]
}
(1 or 2) or (3 or 4 or 5)
{
"item_type":"T_OP_OR",
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST_EXPR",
"CNT_CONST"
],
"rel_id": [
],
"children": [
{
"item_type":"T_OP_BOOL",
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST_EXPR",
"CNT_CONST",
"IS_INNER_ADDED_EXPR"
],
"rel_id": [
],
"children": [
{
"item_type":"T_INT",
"result_type": {
"meta": {
"type":"BIGINT",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":1,
"precision":1,
"scale":0
},
"flag":1,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST",
"CNT_CONST"
],
"rel_id": [
],
"value": {
"BIGINT":1
}
}
]
},
{
"item_type":"T_OP_BOOL",
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST_EXPR",
"CNT_CONST",
"IS_INNER_ADDED_EXPR"
],
"rel_id": [
],
"children": [
{
"item_type":"T_INT",
"result_type": {
"meta": {
"type":"BIGINT",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":1,
"precision":1,
"scale":0
},
"flag":1,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST",
"CNT_CONST"
],
"rel_id": [
],
"value": {
"BIGINT":2
}
}
]
},
{
"item_type":"T_OP_BOOL",
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST_EXPR",
"CNT_CONST",
"IS_INNER_ADDED_EXPR"
],
"rel_id": [
],
"children": [
{
"item_type":"T_INT",
"result_type": {
"meta": {
"type":"BIGINT",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":1,
"precision":1,
"scale":0
},
"flag":1,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST",
"CNT_CONST"
],
"rel_id": [
],
"value": {
"BIGINT":3
}
}
]
},
{
"item_type":"T_OP_BOOL",
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST_EXPR",
"CNT_CONST",
"IS_INNER_ADDED_EXPR"
],
"rel_id": [
],
"children": [
{
"item_type":"T_INT",
"result_type": {
"meta": {
"type":"BIGINT",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":1,
"precision":1,
"scale":0
},
"flag":1,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST",
"CNT_CONST"
],
"rel_id": [
],
"value": {
"BIGINT":4
}
}
]
},
{
"item_type":"T_OP_BOOL",
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST_EXPR",
"CNT_CONST",
"IS_INNER_ADDED_EXPR"
],
"rel_id": [
],
"children": [
{
"item_type":"T_INT",
"result_type": {
"meta": {
"type":"BIGINT",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":1,
"precision":1,
"scale":0
},
"flag":1,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST",
"CNT_CONST"
],
"rel_id": [
],
"value": {
"BIGINT":5
}
}
]
}
]
}
(1 and 2) or (3 and 1) (1 and 2) or (3 and 1)
{ {
"item_type":"T_OP_AND", "item_type":"T_OP_AND",
@ -1441,6 +1741,34 @@ not a between 1 and 100
], ],
"rel_id": [ "rel_id": [
], ],
"children": [
{
"item_type":"T_OP_BOOL",
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST_EXPR",
"CNT_CONST",
"IS_INNER_ADDED_EXPR"
],
"rel_id": [
],
"children": [ "children": [
{ {
"item_type":"T_INT", "item_type":"T_INT",
@ -1471,6 +1799,8 @@ not a between 1 and 100
"value": { "value": {
"BIGINT":1 "BIGINT":1
} }
}
]
}, },
{ {
"item_type":"T_OP_OR", "item_type":"T_OP_OR",
@ -1500,6 +1830,34 @@ not a between 1 and 100
], ],
"rel_id": [ "rel_id": [
], ],
"children": [
{
"item_type":"T_OP_BOOL",
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST_EXPR",
"CNT_CONST",
"IS_INNER_ADDED_EXPR"
],
"rel_id": [
],
"children": [ "children": [
{ {
"item_type":"T_INT", "item_type":"T_INT",
@ -1530,7 +1888,37 @@ not a between 1 and 100
"value": { "value": {
"BIGINT":2 "BIGINT":2
} }
}
]
}, },
{
"item_type":"T_OP_BOOL",
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST_EXPR",
"CNT_CONST",
"IS_INNER_ADDED_EXPR"
],
"rel_id": [
],
"children": [
{ {
"item_type":"T_INT", "item_type":"T_INT",
"result_type": { "result_type": {
@ -1565,6 +1953,8 @@ not a between 1 and 100
} }
] ]
} }
]
}
not(not(a)) not(not(a))
{ {
"item_type":"T_OP_NOT", "item_type":"T_OP_NOT",

View File

@ -637,6 +637,34 @@
], ],
"rel_id": [ "rel_id": [
], ],
"children": [
{
"item_type":"T_OP_BOOL",
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST_EXPR",
"CNT_CONST",
"IS_INNER_ADDED_EXPR"
],
"rel_id": [
],
"children": [ "children": [
{ {
"item_type":"T_INT", "item_type":"T_INT",
@ -667,7 +695,37 @@
"value": { "value": {
"BIGINT":1 "BIGINT":1
} }
}
]
}, },
{
"item_type":"T_OP_BOOL",
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST_EXPR",
"CNT_CONST",
"IS_INNER_ADDED_EXPR"
],
"rel_id": [
],
"children": [
{ {
"item_type":"T_INT", "item_type":"T_INT",
"result_type": { "result_type": {
@ -700,6 +758,8 @@
} }
] ]
} }
]
}
[5] 100 and 0 [5] 100 and 0
{ {
"item_type":"T_OP_AND", "item_type":"T_OP_AND",
@ -727,6 +787,34 @@
], ],
"rel_id": [ "rel_id": [
], ],
"children": [
{
"item_type":"T_OP_BOOL",
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST_EXPR",
"CNT_CONST",
"IS_INNER_ADDED_EXPR"
],
"rel_id": [
],
"children": [ "children": [
{ {
"item_type":"T_INT", "item_type":"T_INT",
@ -757,7 +845,37 @@
"value": { "value": {
"BIGINT":100 "BIGINT":100
} }
}
]
}, },
{
"item_type":"T_OP_BOOL",
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST_EXPR",
"CNT_CONST",
"IS_INNER_ADDED_EXPR"
],
"rel_id": [
],
"children": [
{ {
"item_type":"T_INT", "item_type":"T_INT",
"result_type": { "result_type": {
@ -790,6 +908,8 @@
} }
] ]
} }
]
}
[6] 100 or 0 and 100 [6] 100 or 0 and 100
{ {
"item_type":"T_OP_OR", "item_type":"T_OP_OR",
@ -819,6 +939,34 @@
], ],
"rel_id": [ "rel_id": [
], ],
"children": [
{
"item_type":"T_OP_BOOL",
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST_EXPR",
"CNT_CONST",
"IS_INNER_ADDED_EXPR"
],
"rel_id": [
],
"children": [ "children": [
{ {
"item_type":"T_INT", "item_type":"T_INT",
@ -849,6 +997,8 @@
"value": { "value": {
"BIGINT":100 "BIGINT":100
} }
}
]
}, },
{ {
"item_type":"T_OP_AND", "item_type":"T_OP_AND",
@ -876,6 +1026,34 @@
], ],
"rel_id": [ "rel_id": [
], ],
"children": [
{
"item_type":"T_OP_BOOL",
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST_EXPR",
"CNT_CONST",
"IS_INNER_ADDED_EXPR"
],
"rel_id": [
],
"children": [ "children": [
{ {
"item_type":"T_INT", "item_type":"T_INT",
@ -906,7 +1084,37 @@
"value": { "value": {
"BIGINT":0 "BIGINT":0
} }
}
]
}, },
{
"item_type":"T_OP_BOOL",
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST_EXPR",
"CNT_CONST",
"IS_INNER_ADDED_EXPR"
],
"rel_id": [
],
"children": [
{ {
"item_type":"T_INT", "item_type":"T_INT",
"result_type": { "result_type": {
@ -941,6 +1149,8 @@
} }
] ]
} }
]
}
[7] case name when 'sam' then 'yong' when 'lee' then 'handsome' else 'good' end [7] case name when 'sam' then 'yong' when 'lee' then 'handsome' else 'good' end
{ {
"item_type":"T_OP_ARG_CASE", "item_type":"T_OP_ARG_CASE",
@ -2412,6 +2622,34 @@
], ],
"rel_id": [ "rel_id": [
], ],
"children": [
{
"item_type":"T_OP_BOOL",
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST_EXPR",
"CNT_CONST",
"IS_INNER_ADDED_EXPR"
],
"rel_id": [
],
"children": [ "children": [
{ {
"item_type":"T_INT", "item_type":"T_INT",
@ -2445,6 +2683,8 @@
} }
] ]
} }
]
}
[23] c1+c2=c3+c4 [23] c1+c2=c3+c4
{ {
"item_type":"T_OP_EQ", "item_type":"T_OP_EQ",