Skip to content

Commit e746f45

Browse files
committed
MDEV-20265 Unknown column in field list
This patch corrects the fix of the patch for mdev-19421 that resolved the problem of parsing some embedded join expressions such as t1 join t2 left join t3 on t2.a=t3.a on t1.a=t2.a. Yet the patch contained a bug that prevented proper context analysis of the queries where such expressions were used together with comma separated table references in from clauses.
1 parent ec1f195 commit e746f45

File tree

3 files changed

+460
-28
lines changed

3 files changed

+460
-28
lines changed

mysql-test/r/join.result

Lines changed: 326 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,5 +2921,331 @@ NULL NULL NULL 9
29212921
NULL NULL NULL 5
29222922
drop table t1,t2,t3,t4,s1,s2;
29232923
#
2924+
# MDEV-20265: Mix of comma joins with JOIN expressions
2925+
# (correction of the fix for MDEV-19421)
2926+
# MDEV-20330: duplicate
2927+
#
2928+
create table t1 (a int);
2929+
insert into t1 values (7), (5), (3);
2930+
create table t2 (a int);
2931+
insert into t2 values (5), (1), (7);
2932+
create table t3 (a int);
2933+
insert into t3 values (2), (7), (3);
2934+
create table t4 (a int);
2935+
insert into t4 values (4), (7), (9), (5);
2936+
create table t5 (a int);
2937+
insert into t5 values (3), (7), (9), (2);
2938+
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
2939+
from t1, t2 join t3 left join t4 on t3.a=t4.a;
2940+
id select_type table type possible_keys key key_len ref rows filtered Extra
2941+
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
2942+
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
2943+
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
2944+
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
2945+
Warnings:
2946+
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t1` join `test`.`t2` join `test`.`t3` left join `test`.`t4` on((`test`.`t4`.`a` = `test`.`t3`.`a`)) where 1
2947+
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
2948+
from t1, t2 join t3 left join t4 on t3.a=t4.a;
2949+
t1_a t2_a t3_a t4_a
2950+
7 5 7 7
2951+
5 5 7 7
2952+
3 5 7 7
2953+
7 1 7 7
2954+
5 1 7 7
2955+
3 1 7 7
2956+
7 7 7 7
2957+
5 7 7 7
2958+
3 7 7 7
2959+
7 5 2 NULL
2960+
5 5 2 NULL
2961+
3 5 2 NULL
2962+
7 1 2 NULL
2963+
5 1 2 NULL
2964+
3 1 2 NULL
2965+
7 7 2 NULL
2966+
5 7 2 NULL
2967+
3 7 2 NULL
2968+
7 5 3 NULL
2969+
5 5 3 NULL
2970+
3 5 3 NULL
2971+
7 1 3 NULL
2972+
5 1 3 NULL
2973+
3 1 3 NULL
2974+
7 7 3 NULL
2975+
5 7 3 NULL
2976+
3 7 3 NULL
2977+
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
2978+
from t1, t2 join t3 right join t4 on t3.a=t4.a;
2979+
id select_type table type possible_keys key key_len ref rows filtered Extra
2980+
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
2981+
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (flat, BNL join)
2982+
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
2983+
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
2984+
Warnings:
2985+
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t1` join `test`.`t4` left join (`test`.`t2` join `test`.`t3`) on((`test`.`t3`.`a` = `test`.`t4`.`a`)) where 1
2986+
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
2987+
from t1, t2 join t3 right join t4 on t3.a=t4.a;
2988+
t1_a t2_a t3_a t4_a
2989+
7 5 7 7
2990+
5 5 7 7
2991+
3 5 7 7
2992+
7 1 7 7
2993+
5 1 7 7
2994+
3 1 7 7
2995+
7 7 7 7
2996+
5 7 7 7
2997+
3 7 7 7
2998+
7 NULL NULL 4
2999+
5 NULL NULL 4
3000+
3 NULL NULL 4
3001+
7 NULL NULL 9
3002+
5 NULL NULL 9
3003+
3 NULL NULL 9
3004+
7 NULL NULL 5
3005+
5 NULL NULL 5
3006+
3 NULL NULL 5
3007+
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
3008+
from t1, t2 join t3 join t4 left join t5 on t4.a=t5.a;
3009+
id select_type table type possible_keys key key_len ref rows filtered Extra
3010+
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
3011+
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
3012+
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
3013+
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (incremental, BNL join)
3014+
1 SIMPLE t5 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
3015+
Warnings:
3016+
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a`,`test`.`t5`.`a` AS `t5_a` from `test`.`t1` join `test`.`t2` join `test`.`t3` join `test`.`t4` left join `test`.`t5` on((`test`.`t5`.`a` = `test`.`t4`.`a`)) where 1
3017+
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
3018+
from t1, t2 join t3 join t4 left join t5 on t4.a=t5.a;
3019+
t1_a t2_a t3_a t4_a t5_a
3020+
7 5 2 7 7
3021+
5 5 2 7 7
3022+
3 5 2 7 7
3023+
7 1 2 7 7
3024+
5 1 2 7 7
3025+
3 1 2 7 7
3026+
7 7 2 7 7
3027+
5 7 2 7 7
3028+
3 7 2 7 7
3029+
7 5 7 7 7
3030+
5 5 7 7 7
3031+
3 5 7 7 7
3032+
7 1 7 7 7
3033+
5 1 7 7 7
3034+
3 1 7 7 7
3035+
7 7 7 7 7
3036+
5 7 7 7 7
3037+
3 7 7 7 7
3038+
7 5 3 7 7
3039+
5 5 3 7 7
3040+
3 5 3 7 7
3041+
7 1 3 7 7
3042+
5 1 3 7 7
3043+
3 1 3 7 7
3044+
7 7 3 7 7
3045+
5 7 3 7 7
3046+
3 7 3 7 7
3047+
7 5 2 9 9
3048+
5 5 2 9 9
3049+
3 5 2 9 9
3050+
7 1 2 9 9
3051+
5 1 2 9 9
3052+
3 1 2 9 9
3053+
7 7 2 9 9
3054+
5 7 2 9 9
3055+
3 7 2 9 9
3056+
7 5 7 9 9
3057+
5 5 7 9 9
3058+
3 5 7 9 9
3059+
7 1 7 9 9
3060+
5 1 7 9 9
3061+
3 1 7 9 9
3062+
7 7 7 9 9
3063+
5 7 7 9 9
3064+
3 7 7 9 9
3065+
7 5 3 9 9
3066+
5 5 3 9 9
3067+
3 5 3 9 9
3068+
7 1 3 9 9
3069+
5 1 3 9 9
3070+
3 1 3 9 9
3071+
7 7 3 9 9
3072+
5 7 3 9 9
3073+
3 7 3 9 9
3074+
7 5 2 4 NULL
3075+
5 5 2 4 NULL
3076+
3 5 2 4 NULL
3077+
7 1 2 4 NULL
3078+
5 1 2 4 NULL
3079+
3 1 2 4 NULL
3080+
7 7 2 4 NULL
3081+
5 7 2 4 NULL
3082+
3 7 2 4 NULL
3083+
7 5 7 4 NULL
3084+
5 5 7 4 NULL
3085+
3 5 7 4 NULL
3086+
7 1 7 4 NULL
3087+
5 1 7 4 NULL
3088+
3 1 7 4 NULL
3089+
7 7 7 4 NULL
3090+
5 7 7 4 NULL
3091+
3 7 7 4 NULL
3092+
7 5 3 4 NULL
3093+
5 5 3 4 NULL
3094+
3 5 3 4 NULL
3095+
7 1 3 4 NULL
3096+
5 1 3 4 NULL
3097+
3 1 3 4 NULL
3098+
7 7 3 4 NULL
3099+
5 7 3 4 NULL
3100+
3 7 3 4 NULL
3101+
7 5 2 5 NULL
3102+
5 5 2 5 NULL
3103+
3 5 2 5 NULL
3104+
7 1 2 5 NULL
3105+
5 1 2 5 NULL
3106+
3 1 2 5 NULL
3107+
7 7 2 5 NULL
3108+
5 7 2 5 NULL
3109+
3 7 2 5 NULL
3110+
7 5 7 5 NULL
3111+
5 5 7 5 NULL
3112+
3 5 7 5 NULL
3113+
7 1 7 5 NULL
3114+
5 1 7 5 NULL
3115+
3 1 7 5 NULL
3116+
7 7 7 5 NULL
3117+
5 7 7 5 NULL
3118+
3 7 7 5 NULL
3119+
7 5 3 5 NULL
3120+
5 5 3 5 NULL
3121+
3 5 3 5 NULL
3122+
7 1 3 5 NULL
3123+
5 1 3 5 NULL
3124+
3 1 3 5 NULL
3125+
7 7 3 5 NULL
3126+
5 7 3 5 NULL
3127+
3 7 3 5 NULL
3128+
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
3129+
from t1, t2 join t3 join t4 right join t5 on t4.a=t5.a;
3130+
id select_type table type possible_keys key key_len ref rows filtered Extra
3131+
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
3132+
1 SIMPLE t5 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (flat, BNL join)
3133+
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
3134+
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
3135+
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
3136+
Warnings:
3137+
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a`,`test`.`t5`.`a` AS `t5_a` from `test`.`t1` join `test`.`t5` left join (`test`.`t2` join `test`.`t3` join `test`.`t4`) on((`test`.`t4`.`a` = `test`.`t5`.`a`)) where 1
3138+
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
3139+
from t1, t2 join t3 join t4 right join t5 on t4.a=t5.a;
3140+
t1_a t2_a t3_a t4_a t5_a
3141+
7 5 2 7 7
3142+
5 5 2 7 7
3143+
3 5 2 7 7
3144+
7 1 2 7 7
3145+
5 1 2 7 7
3146+
3 1 2 7 7
3147+
7 7 2 7 7
3148+
5 7 2 7 7
3149+
3 7 2 7 7
3150+
7 5 7 7 7
3151+
5 5 7 7 7
3152+
3 5 7 7 7
3153+
7 1 7 7 7
3154+
5 1 7 7 7
3155+
3 1 7 7 7
3156+
7 7 7 7 7
3157+
5 7 7 7 7
3158+
3 7 7 7 7
3159+
7 5 3 7 7
3160+
5 5 3 7 7
3161+
3 5 3 7 7
3162+
7 1 3 7 7
3163+
5 1 3 7 7
3164+
3 1 3 7 7
3165+
7 7 3 7 7
3166+
5 7 3 7 7
3167+
3 7 3 7 7
3168+
7 5 2 9 9
3169+
5 5 2 9 9
3170+
3 5 2 9 9
3171+
7 1 2 9 9
3172+
5 1 2 9 9
3173+
3 1 2 9 9
3174+
7 7 2 9 9
3175+
5 7 2 9 9
3176+
3 7 2 9 9
3177+
7 5 7 9 9
3178+
5 5 7 9 9
3179+
3 5 7 9 9
3180+
7 1 7 9 9
3181+
5 1 7 9 9
3182+
3 1 7 9 9
3183+
7 7 7 9 9
3184+
5 7 7 9 9
3185+
3 7 7 9 9
3186+
7 5 3 9 9
3187+
5 5 3 9 9
3188+
3 5 3 9 9
3189+
7 1 3 9 9
3190+
5 1 3 9 9
3191+
3 1 3 9 9
3192+
7 7 3 9 9
3193+
5 7 3 9 9
3194+
3 7 3 9 9
3195+
7 NULL NULL NULL 3
3196+
5 NULL NULL NULL 3
3197+
3 NULL NULL NULL 3
3198+
7 NULL NULL NULL 2
3199+
5 NULL NULL NULL 2
3200+
3 NULL NULL NULL 2
3201+
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
3202+
from t1 left join t2 on t1.a=t2.a, t3 join t4 right join t5 on t4.a=t5.a;
3203+
id select_type table type possible_keys key key_len ref rows filtered Extra
3204+
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
3205+
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
3206+
1 SIMPLE t5 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (incremental, BNL join)
3207+
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
3208+
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
3209+
Warnings:
3210+
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a`,`test`.`t5`.`a` AS `t5_a` from `test`.`t1` left join `test`.`t2` on((`test`.`t2`.`a` = `test`.`t1`.`a`)) join `test`.`t5` left join (`test`.`t3` join `test`.`t4`) on((`test`.`t4`.`a` = `test`.`t5`.`a`)) where 1
3211+
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
3212+
from t1 left join t2 on t1.a=t2.a, t3 join t4 right join t5 on t4.a=t5.a;
3213+
t1_a t2_a t3_a t4_a t5_a
3214+
5 5 2 7 7
3215+
7 7 2 7 7
3216+
3 NULL 2 7 7
3217+
5 5 7 7 7
3218+
7 7 7 7 7
3219+
3 NULL 7 7 7
3220+
5 5 3 7 7
3221+
7 7 3 7 7
3222+
3 NULL 3 7 7
3223+
5 5 2 9 9
3224+
7 7 2 9 9
3225+
3 NULL 2 9 9
3226+
5 5 7 9 9
3227+
7 7 7 9 9
3228+
3 NULL 7 9 9
3229+
5 5 3 9 9
3230+
7 7 3 9 9
3231+
3 NULL 3 9 9
3232+
5 5 NULL NULL 3
3233+
7 7 NULL NULL 3
3234+
3 NULL NULL NULL 3
3235+
5 5 NULL NULL 2
3236+
7 7 NULL NULL 2
3237+
3 NULL NULL NULL 2
3238+
drop table t1,t2,t3,t4,t5;
3239+
select a.a
3240+
from (select 1 as a) a,
3241+
(select 2 as b) b
3242+
cross join
3243+
(select 3 as c) c
3244+
left join
3245+
(select 4 as d) d
3246+
on 1;
3247+
a
3248+
1
3249+
#
29243250
# End of MariaDB 5.5 tests
29253251
#

mysql-test/t/join.test

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,65 @@ eval $q;
16131613

16141614
drop table t1,t2,t3,t4,s1,s2;
16151615

1616+
--echo #
1617+
--echo # MDEV-20265: Mix of comma joins with JOIN expressions
1618+
--echo # (correction of the fix for MDEV-19421)
1619+
--echo # MDEV-20330: duplicate
1620+
--echo #
1621+
1622+
create table t1 (a int);
1623+
insert into t1 values (7), (5), (3);
1624+
create table t2 (a int);
1625+
insert into t2 values (5), (1), (7);
1626+
create table t3 (a int);
1627+
insert into t3 values (2), (7), (3);
1628+
create table t4 (a int);
1629+
insert into t4 values (4), (7), (9), (5);
1630+
create table t5 (a int);
1631+
insert into t5 values (3), (7), (9), (2);
1632+
1633+
1634+
let $q=
1635+
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
1636+
from t1, t2 join t3 left join t4 on t3.a=t4.a;
1637+
eval explain extended $q;
1638+
eval $q;
1639+
1640+
let $q=
1641+
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
1642+
from t1, t2 join t3 right join t4 on t3.a=t4.a;
1643+
eval explain extended $q;
1644+
eval $q;
1645+
1646+
let $q=
1647+
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
1648+
from t1, t2 join t3 join t4 left join t5 on t4.a=t5.a;
1649+
eval explain extended $q;
1650+
eval $q;
1651+
1652+
let $q=
1653+
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
1654+
from t1, t2 join t3 join t4 right join t5 on t4.a=t5.a;
1655+
eval explain extended $q;
1656+
eval $q;
1657+
1658+
let $q=
1659+
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
1660+
from t1 left join t2 on t1.a=t2.a, t3 join t4 right join t5 on t4.a=t5.a;
1661+
eval explain extended $q;
1662+
eval $q;
1663+
1664+
drop table t1,t2,t3,t4,t5;
1665+
1666+
select a.a
1667+
from (select 1 as a) a,
1668+
(select 2 as b) b
1669+
cross join
1670+
(select 3 as c) c
1671+
left join
1672+
(select 4 as d) d
1673+
on 1;
1674+
16161675
--echo #
16171676
--echo # End of MariaDB 5.5 tests
16181677
--echo #

0 commit comments

Comments
 (0)