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": {
@ -1412,6 +1380,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)
{ {
@ -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": {
@ -1564,6 +1952,8 @@ not a between 1 and 100
] ]
} }
] ]
}
]
} }
not(not(a)) not(not(a))
{ {

View File

@ -639,19 +639,19 @@
], ],
"children": [ "children": [
{ {
"item_type":"T_INT", "item_type":"T_OP_BOOL",
"result_type": { "result_type": {
"meta": { "meta": {
"type":"BIGINT", "type":"",
"collation":"binary", "collation":"binary",
"coercibility":"NUMERIC" "coercibility":"NUMERIC"
}, },
"accuracy": { "accuracy": {
"length":1, "length":-1,
"precision":1, "precision":-1,
"scale":0 "scale":-1
}, },
"flag":1, "flag":0,
"calc_type": { "calc_type": {
"type":"NULL", "type":"NULL",
"collation":"invalid_type", "collation":"invalid_type",
@ -659,15 +659,13 @@
} }
}, },
"expr_info": [ "expr_info": [
"IS_CONST", "IS_CONST_EXPR",
"CNT_CONST" "CNT_CONST",
"IS_INNER_ADDED_EXPR"
], ],
"rel_id": [ "rel_id": [
], ],
"value": { "children": [
"BIGINT":1
}
},
{ {
"item_type":"T_INT", "item_type":"T_INT",
"result_type": { "result_type": {
@ -699,6 +697,68 @@
} }
} }
] ]
},
{
"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
}
}
]
}
]
} }
[5] 100 and 0 [5] 100 and 0
{ {
@ -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": {
@ -789,6 +907,8 @@
} }
} }
] ]
}
]
} }
[6] 100 or 0 and 100 [6] 100 or 0 and 100
{ {
@ -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": {
@ -940,6 +1148,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
{ {
@ -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",
@ -2444,6 +2682,8 @@
} }
} }
] ]
}
]
} }
[23] c1+c2=c3+c4 [23] c1+c2=c3+c4
{ {