Bug #40358 HA_KEY_HAS_PART_KEY_SEG does not properly get passed to storage engine

Submitted: 27 Oct 2008 19:34 Modified: 9 Jul 2009 15:06
Reporter: Zardosht Kasheff (OCA) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.1.28 OS:Any
Assigned to: Alexander Nozdrin CPU Architecture:Any
Tags: HA_KEY_HAS_PART_KEY_SEG

[27 Oct 2008 19:34] Zardosht Kasheff
Description:
The flag HA_KEY_HAS_PART_KEY_SEG does not get passed to storage engines in the key->flags.

The reason is the following. Although properly set in mysql_prepare_create_table, in the function pack_keys in unireg.cc, only 2 bytes are stored for a key's flags. This causes HA_KEY_HAS_PART_KEY_SEG to be truncated, because it maps to 0x10000.

How to repeat:
Do the following:
create table foo (a varchar(10), b int, key (a(3)));

Break in mysqld!pack_keys

Notice how keyinfo[0].flags = 0x10040

Break in mysqld!ha_myisam::create

Notice how table_arg->key_info[0].flags = 0x40

Suggested fix:
4 bytes should be stored for a key's flags. KEY->flags is a ulong, so it makes sense to store more than 2 bytes.
[28 Oct 2008 0:12] MySQL Verification Team
Thank you for the bug report. Verified as described:

-	keyinfo	0x01f4efc0 {key_length=0x00000009 flags=0x00010068 key_parts=0x00000001 ...}	st_key *
	key_length	0x00000009	unsigned int
	flags	0x00010068	unsigned long
	key_parts	0x00000001	unsigned int
	extra_length	0x00000000	unsigned int
	usable_key_parts	0x00000000	unsigned int
	block_size	0x00000000	unsigned int
	algorithm	HA_KEY_ALG_UNDEF	ha_key_alg
+	parser	0x00000000	st_plugin_int * *
<cut>

-	table_arg	0x0392d8ac {s=0x0392d458 {table_category=TABLE_CATEGORY_USER name_hash={key_offset=0x00000000 key_length=0x00000000 blength=0x00000000 ...} mem_root={free=0x01f2dc50 {next=0x00000000 left=0x000000f8 size=0x000003c8 } used=0x00000000 {next=??? left=??? size=??? } pre_alloc=0x00000000 {next=??? left=??? size=??? } ...} ...} file=0x01f54a10 {file=0x00000000 {s=??? state=??? save_state={records=??? del=??? empty=??? ...} ...} int_table_flags=0x0000000d14626d91 data_file_name=0xa5a5a5a5 <Bad Ptr> ...} next=0x00000000 {s=??? file=??? next=??? ...} ...}	st_table *
<cut>
-	key_info	0x01f54c40 {key_length=0x0000000c flags=0x00000068 key_parts=0x00000001 ...}	st_key *
	key_length	0x0000000c	unsigned int
	flags	0x00000068	unsigned long
	key_parts	0x00000001	unsigned int
	extra_length	0x00000003	unsigned int
	usable_key_parts	0x00000001	unsigned int
	block_size	0x00000000	unsigned int
	algorithm	HA_KEY_ALG_UNDEF	ha_key_alg
+	parser	0x00000000	st_plugin_int * *
<cut>
[9 Jul 2009 6:35] Alexander Nozdrin
I discussed this issue with Sergei Golubchik.

It is not a bug, because HA_KEY_HAS_PART_KEY_SEG flag is
internal to the MySQL server by design. It is not supposed
neither to be saved in FRM-files, nor to be passed to storage
engines (it's intended to pass information into internal
static sort_keys(KEY *, KEY *) function)

This flag can actually be calculated -- it's based on key lengths
comparison. So, a storage engine can determine it by itself.
[9 Jul 2009 15:06] Zardosht Kasheff
The main motivation for filing this bug is that the fact that the .frm file only uses 2 bytes to store key flags can be a problem. The internal data structure uses 4 bytes. So, the key flags cannot be extended. I will file a separate bug on this.
[9 Jul 2009 16:30] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/78300

2826 Alexander Nozdrin	2009-07-09
      Add a comment in the source (Bug#40358).
[23 Jul 2009 10:24] Bugs System
Pushed into 5.4.4-alpha (revid:alik@sun.com-20090723102221-ps4uaphwbxzj8p0q) (version source revid:alik@sun.com-20090709163043-2gf8cgh583hjcbr4) (merge vers: 5.4.4-alpha) (pib:11)
[16 Oct 2009 15:22] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/87159

2931 Alexander Nozdrin	2009-10-16
      Backporting revision from 6.0:
      revno: 2617.56.25
      committer: Alexander Nozdrin <alik@sun.com>
      branch nick: azalea-bugfixing
      timestamp: Thu 2009-07-09 20:30:43 +0400
      message:
        Add a comment in the source (Bug#40358).
[3 Nov 2009 7:16] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20091102151658-j9o4wgro47m5v84d) (version source revid:alik@sun.com-20091023064702-2f8jdmny61bdl94u) (merge vers: 6.0.14-alpha) (pib:13)
[12 Nov 2009 8:19] Bugs System
Pushed into 5.5.0-beta (revid:alik@sun.com-20091110093229-0bh5hix780cyeicl) (version source revid:mikael@mysql.com-20091103113702-p61dlwc6ml6fxg18) (merge vers: 5.5.0-beta) (pib:13)

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.063 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.