[MDEV-32038] "Invalid use of group function" on 2nd execution of PS for SELECT from view created with aggregate functions Created: 2023-08-30  Updated: 2023-11-28

Status: Open
Project: MariaDB Server
Component/s: Prepared Statements
Affects Version/s: 10.4, 10.5, 10.6, 10.10, 10.11, 11.0, 11.1, 11.2, 11.3
Fix Version/s: 10.4, 10.5, 10.6, 10.11, 11.0, 11.1, 11.2, 11.3

Type: Bug Priority: Major
Reporter: Lena Startseva Assignee: Dmitry Shulga
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-31933 Make working view-protocol + ps-prot... Stalled

 Description   

After fix enable "ps2-protocol" for cases marked with MDEV-32038

Testcase:

CREATE TABLE t1 (a int, b INT, d INT, c CHAR(10) NOT NULL, PRIMARY KEY (a, b));
INSERT INTO t1 VALUES (1,1,0,'a'), (1,2,0,'b'), (1,3,0,'c'), (1,4,0,'d'),
(1,5,0,'e'), (2,1,0,'f'), (2,2,0,'g'), (2,3,0,'h'), (3,4,0,'i'), (3,3,0,'j'),
(3,2,0,'k'), (3,1,0,'l'), (1,9,0,'m'), (1,0,10,'n'), (2,0,5,'o'), (3,0,7,'p');
 
create view v1 as SELECT tt.a,
 (SELECT (SELECT c FROM t1 as t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a)
  LIMIT 1) FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1) as test
  FROM t1 as tt;
 
prepare stmt from "select * from v1";
 
execute stmt;
execute stmt;
 
deallocate prepare stmt;
 
drop view v1;
 
DROP TABLE t1;

Actual value:

prepare stmt from "select * from v1";
execute stmt;
a	test
1	n
1	n
1	n
1	n
1	n
1	n
1	n
2	o
2	o
2	o
2	o
3	p
3	p
3	p
3	p
3	p
execute stmt;
 
mysqltest: At line 14: query 'execute stmt' failed: ER_INVALID_GROUP_FUNC_USE (1111): Invalid use of group function

Expected value:

prepare stmt from "select * from v1";
execute stmt;
a	test
1	n
1	n
1	n
1	n
1	n
1	n
1	n
2	o
2	o
2	o
2	o
3	p
3	p
3	p
3	p
3	p
execute stmt;
a	test
1	n
1	n
1	n
1	n
1	n
1	n
1	n
2	o
2	o
2	o
2	o
3	p
3	p
3	p
3	p
3	p


Generated at Thu Feb 08 10:28:21 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.