[MCOL-3890] insert.. select * from (subselect) throw "is not in GROUP BY clause" , even if it is part of group by clause Created: 2020-03-17  Updated: 2021-03-24  Resolved: 2021-03-24

Status: Closed
Project: MariaDB ColumnStore
Component/s: N/A
Affects Version/s: 1.4.3
Fix Version/s: 5.6.1

Type: Bug Priority: Major
Reporter: Richard Stracke Assignee: Roman
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Issue split
split to MCOL-4637 select * into file from (select ... g... Open
Problem/Incident
is caused by MDEV-24298 SELECT_LEX::find_select_handler() fai... Closed
Relates
Sprint: 2020-7, 2021-5

 Description   

Testcase to reproduce:

drop table if exists `I1`;
drop table if exists `C2`;
 
 
 
 CREATE TABLE `I1` (
  `id` int(11) DEFAULT NULL,
  `intc` int(11) DEFAULT NULL
 
) ENGINE=Columnstore DEFAULT CHARSET=utf8;
 
 
CREATE TABLE `C2` (
  `intc` int(6) DEFAULT NULL,
`id` int(11) NOT NULL,
 `mm_prezzo` decimal(12,0) DEFAULT NULL
) ENGINE=Columnstore DEFAULT CHARSET=utf8;
 
 
INSERT INTO I1
select * from (SELECT id,intc
FROM C2
WHERE  intc IN (201909)
GROUP BY id,intc) as sel1;

Cause:

ERROR 1815 (HY000): Internal error: IDB-2021: 'intc' is not in GROUP BY clause. All non-aggregate columns in the SELECT and ORDER BY clause must be included in the GROUP BY clause.

The select works without insert part,
It works ,without where condition "WHERE intc IN (201909)"
It works with opposite order in group by ("intc,id" instead "id,intc")



 Comments   
Comment by Roman [ 2020-03-23 ]

So the issue caused by the optimization made by MDB. It removes intc b/c there is IN + single constant. If you run the query with at least two constants it works. If you switch the GROUP BY order it works b/c GROUP BY key is now 2 columns not one.

There is a fix ready for this issue.

Next release will both contain a workaround that enables SH for INSERT..SELECT and fix for Derived Handler.

Comment by Roman [ 2020-04-02 ]

4 QA: you should also test:

create table t2 as select * from (SELECT id,intc FROM C2 WHERE intc IN (201909) GROUP BY id,intc) as sel1;
select * into outfile '/tmp/result.dml' from (SELECT id,intc FROM C2 WHERE intc IN (201909) GROUP BY id,intc) as sel1;

Comment by Roman [ 2020-05-08 ]

Had been solved in the hotfix for 1.4.3.

Comment by Roman [ 2020-05-08 ]

The corner case(single top level subquery wrap) described by this issue fails in 1.4 and 1.5.
MDB doesn't find SH b/c SELECT_LEX::find_select_handler() gets only a subquery TABLE that can't ColumnStore handler.

Comment by Gregory Dorman (Inactive) [ 2021-03-23 ]

I just retested it and it works in 5.5.2. There was an MDEV ticket which is responsible for fixing it - but of course I can't fine it (maybe drrtuy can recover it).

In either case, let's formally test it in 5.6.1 branch (5.5.2 is too late), so at lease we will be able to get it into the release notes and tell the world that it is fixed then.

Comment by Daniel Lee (Inactive) [ 2021-03-23 ]

Build tested: 5.6.1 (Drone #1915)

The issue reported in the bug description has been fixed, but another issue mentioned in the comment still exists.

MariaDB [mytest]> create table t2 as select * from (SELECT id,intc FROM C2 WHERE intc IN (201909) GROUP BY id,intc) as sel1;
Query OK, 0 rows affected (0.016 sec)
Records: 0 Duplicates: 0 Warnings: 0

MariaDB [mytest]> select * into outfile '/tmp/result.dml' from (SELECT id,intc FROM C2 WHERE intc IN (201909) GROUP BY id,intc) as sel1;
ERROR 1815 (HY000): Internal error: IDB-2021: 'intc' is not in GROUP BY clause. All non-aggregate columns in the SELECT and ORDER BY clause must be included in the GROUP BY clause.

The query would work without the outfile clause

MariaDB [mytest]> select * from (SELECT id,intc FROM C2 WHERE intc IN (201909) GROUP BY id,intc) as sel1;
Empty set (0.011 sec)

Comment by Gregory Dorman (Inactive) [ 2021-03-24 ]

The original complaint has been corrected by MDEV-24298 and verified in 5.5.2 by GD and in develop by Daniel. New ticket - MCOL-4637 was created to deal with the ajacent problem (same error message this time on select into file)

Generated at Thu Feb 08 02:46:13 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.