@@ -4095,6 +4095,116 @@ MIN(pk) a
409540955 10
40964096DROP TABLE t1;
40974097#
4098+ # MDEV-6768 Wrong result with agregate with join with no resultset
4099+ #
4100+ create table t1
4101+ (
4102+ PARENT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
4103+ PARENT_FIELD VARCHAR(10),
4104+ PRIMARY KEY (PARENT_ID)
4105+ ) engine=innodb;
4106+ create table t2
4107+ (
4108+ CHILD_ID INT NOT NULL AUTO_INCREMENT,
4109+ PARENT_ID INT NOT NULL,
4110+ CHILD_FIELD varchar(10),
4111+ PRIMARY KEY (CHILD_ID)
4112+ )engine=innodb;
4113+ INSERT INTO t1 (PARENT_FIELD)
4114+ SELECT 'AAAA';
4115+ INSERT INTO t2 (PARENT_ID, CHILD_FIELD)
4116+ SELECT 1, 'BBBB';
4117+ explain select
4118+ t1.PARENT_ID,
4119+ min(CHILD_FIELD)
4120+ from t1 straight_join t2
4121+ where t1.PARENT_ID = 1
4122+ and t1.PARENT_ID = t2.PARENT_ID
4123+ and t2.CHILD_FIELD = "ZZZZ";
4124+ id select_type table type possible_keys key key_len ref rows Extra
4125+ 1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 Using index
4126+ 1 SIMPLE t2 ALL NULL NULL NULL NULL 1 Using where
4127+ select
4128+ t1.PARENT_ID,
4129+ min(CHILD_FIELD)
4130+ from t1 straight_join t2
4131+ where t1.PARENT_ID = 1
4132+ and t1.PARENT_ID = t2.PARENT_ID
4133+ and t2.CHILD_FIELD = "ZZZZ";
4134+ PARENT_ID min(CHILD_FIELD)
4135+ NULL NULL
4136+ select
4137+ 1,
4138+ min(CHILD_FIELD)
4139+ from t1 straight_join t2
4140+ where t1.PARENT_ID = 1
4141+ and t1.PARENT_ID = t2.PARENT_ID
4142+ and t2.CHILD_FIELD = "ZZZZ";
4143+ 1 min(CHILD_FIELD)
4144+ 1 NULL
4145+ select
4146+ IFNULL(t1.PARENT_ID,1),
4147+ min(CHILD_FIELD)
4148+ from t1 straight_join t2
4149+ where t1.PARENT_ID = 1
4150+ and t1.PARENT_ID = t2.PARENT_ID
4151+ and t2.CHILD_FIELD = "ZZZZ";
4152+ IFNULL(t1.PARENT_ID,1) min(CHILD_FIELD)
4153+ 1 NULL
4154+ # Check that things works with MyISAM (which has different explain)
4155+ alter table t1 engine=myisam;
4156+ alter table t2 engine=myisam;
4157+ explain select
4158+ t1.PARENT_ID,
4159+ min(CHILD_FIELD)
4160+ from t1 straight_join t2
4161+ where t1.PARENT_ID = 1
4162+ and t1.PARENT_ID = t2.PARENT_ID
4163+ and t2.CHILD_FIELD = "ZZZZ";
4164+ id select_type table type possible_keys key key_len ref rows Extra
4165+ 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
4166+ select
4167+ t1.PARENT_ID,
4168+ min(CHILD_FIELD)
4169+ from t1 straight_join t2
4170+ where t1.PARENT_ID = 1
4171+ and t1.PARENT_ID = t2.PARENT_ID
4172+ and t2.CHILD_FIELD = "ZZZZ";
4173+ PARENT_ID min(CHILD_FIELD)
4174+ NULL NULL
4175+ drop table t1,t2;
4176+ # Check that things works if sub queries are re-executed
4177+ create table t1 (a int primary key, b int);
4178+ create table t2 (a int primary key, b int);
4179+ create table t3 (a int primary key, b int);
4180+ insert into t1 values (1,1),(2,2),(3,3);
4181+ insert into t2 values (1,1),(2,2),(3,3);
4182+ insert into t3 values (1,1),(3,3);
4183+ explain
4184+ select *,
4185+ (select
4186+ CONCAT('t2:', IFNULL(t2.a, 't2a-null'), ';',
4187+ 'min_t3_b:', IFNULL(min(t3.b), 't3b-null'))
4188+ from t2,t3
4189+ where t2.a=1 and t1.b = t3.a) as s1
4190+ from t1;
4191+ id select_type table type possible_keys key key_len ref rows Extra
4192+ 1 PRIMARY t1 ALL NULL NULL NULL NULL 3
4193+ 2 DEPENDENT SUBQUERY t2 const PRIMARY PRIMARY 4 const 1 Using index
4194+ 2 DEPENDENT SUBQUERY t3 eq_ref PRIMARY PRIMARY 4 test.t1.b 1
4195+ select *,
4196+ (select
4197+ CONCAT('t2:', IFNULL(t2.a, 't2a-null'), ';',
4198+ 'min_t3_b:', IFNULL(min(t3.b), 't3b-null'))
4199+ from t2,t3
4200+ where t2.a=1 and t1.b = t3.a) as s1
4201+ from t1;
4202+ a b s1
4203+ 1 1 t2:1;min_t3_b:1
4204+ 2 2 t2:t2a-null;min_t3_b:t3b-null
4205+ 3 3 t2:1;min_t3_b:3
4206+ drop table t1,t2,t3;
4207+ #
40984208# End of 10.5 tests
40994209#
41004210#
0 commit comments