[MDEV-20681] Aria temptable used for grouping may have key longer than maria_max_key_length() Created: 2019-09-26  Updated: 2021-02-17  Resolved: 2021-02-14

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - Aria
Affects Version/s: 10.3, 10.4
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Sergei Petrunia Assignee: Sergei Golubchik
Resolution: Not a Bug Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-20279 Increase Aria index length limit Closed

 Description   

Consider this testcase:

create table ten(a int primary key);
insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
 
create table one_k(a int primary key);
insert into one_k select A.a + B.a* 10 + C.a * 100 from ten A, ten B, ten C;
 
create table t21 (
  a varchar(500) COLLATE utf8mb4_bin
);
insert into t21 select A.a+1000*B.a  from one_k A, one_k B;
 
set max_heap_table_size=32000; # just some low value to overflow the heap table.

Put a breakpoint in create_internal_tmp_table_from_heap, then run

select conc_val, count(*) from  t21 group by conc_val ;

when the Aria table is created, one can see:

(gdb) p maria_max_key_length()
  $53 = 1000
(gdb) p this
  $55 = (ha_maria * const) 0x7fff6c165f38
(gdb) p table->key_info[0]
  $57 = {key_length = 2000, flags = 2083, user_defined_key_parts = 1, ...

So, key_length larger than maria_max_key_length().

I didn't see this produce any problem, except that it might be confusing for
the users. How come GROUP BY code can use a unique key of this length, while
SJ-Materialization is not applicable for such long keys?



 Comments   
Comment by Michael Widenius [ 2021-02-14 ]

This is because if a key for an internal temporary is longer than maria_max_key_length, it changes the key to an internal unique key, which can have any size. This is why we can DISTINCT and GROUP BY over anything without any size limitations.

Comment by Michael Widenius [ 2021-02-14 ]

See comment

Comment by Sergei Golubchik [ 2021-02-17 ]

SJ-Materialization, as an internal optimization, perhaps could be able to use that too

Generated at Thu Feb 08 09:01:22 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.