Skip to content

Commit 59d7666

Browse files
committed
MariaRocks port: Return correct value of HA_PRIMARY_KEY_IN_READ_INDEX flag
This cset just re-uses the approach from facebook/mysql-5.6 (Perhaps we will have something different for MariaDB in the end). For now this is: Port this fix dd7eeae69503cb8ab6ddc8fd9e2fef451cc31a32 Issue#250: MyRocks/Innodb different output from query with order by on table with index and decimal type Summary: Make open_binary_frm() set TABLE_SHARE::primary_key before it computes Also add the patch for facebook/mysql-5.6#376
1 parent f2219fe commit 59d7666

File tree

6 files changed

+57
-16
lines changed

6 files changed

+57
-16
lines changed

sql/ha_partition.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,22 @@ ha_partition::~ha_partition()
421421
}
422422

423423

424+
bool ha_partition::init_with_fields()
425+
{
426+
/* Pass the call to each partition */
427+
for (uint i= 0; i < m_tot_parts; i++)
428+
{
429+
if (m_file[i]->init_with_fields())
430+
return true;
431+
}
432+
/* Re-read table flags in case init_with_fields caused it to change */
433+
cached_table_flags= (m_file[0]->ha_table_flags() &
434+
~(PARTITION_DISABLED_TABLE_FLAGS)) |
435+
PARTITION_ENABLED_TABLE_FLAGS;
436+
return false;
437+
}
438+
439+
424440
/*
425441
Initialize partition handler object
426442

sql/ha_partition.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ class ha_partition :public handler
307307
ha_partition *clone_arg,
308308
MEM_ROOT *clone_mem_root_arg);
309309
~ha_partition();
310+
311+
bool init_with_fields();
310312
/*
311313
A partition handler has no characteristics in itself. It only inherits
312314
those from the underlying handlers. Here we set-up those constants to

sql/handler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2757,6 +2757,8 @@ class handler :public Sql_alloc
27572757
{
27582758
cached_table_flags= table_flags();
27592759
}
2760+
2761+
virtual bool init_with_fields() { return false; }
27602762
/* ha_ methods: pubilc wrappers for private virtual API */
27612763

27622764
int ha_open(TABLE *table, const char *name, int mode, uint test_if_locked);

sql/table.cc

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,18 +2061,6 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
20612061
if (key == primary_key)
20622062
{
20632063
field->flags|= PRI_KEY_FLAG;
2064-
/*
2065-
If this field is part of the primary key and all keys contains
2066-
the primary key, then we can use any key to find this column
2067-
*/
2068-
if (ha_option & HA_PRIMARY_KEY_IN_READ_INDEX)
2069-
{
2070-
if (field->key_length() == key_part->length &&
2071-
!(field->flags & BLOB_FLAG))
2072-
field->part_of_key= share->keys_in_use;
2073-
if (field->part_of_sortkey.is_set(key))
2074-
field->part_of_sortkey= share->keys_in_use;
2075-
}
20762064
}
20772065
if (field->key_length() != key_part->length)
20782066
{
@@ -2132,6 +2120,38 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
21322120
(ha_option & HA_ANY_INDEX_MAY_BE_UNIQUE))
21332121
set_if_bigger(share->max_unique_length,keyinfo->key_length);
21342122
}
2123+
2124+
/*
2125+
The next call is here for MyRocks/MariaRocks: Now, we have filled in
2126+
field and key definitions, give the storage engine a chance to adjust
2127+
its properties.
2128+
2129+
MyRocks may (and typically does) adjust HA_PRIMARY_KEY_IN_READ_INDEX
2130+
flag in this call.
2131+
*/
2132+
if (handler_file->init_with_fields())
2133+
goto err;
2134+
2135+
if (primary_key < MAX_KEY && (handler_file->ha_table_flags() &
2136+
HA_PRIMARY_KEY_IN_READ_INDEX))
2137+
{
2138+
keyinfo= &share->key_info[primary_key];
2139+
key_part= keyinfo->key_part;
2140+
for (i=0 ; i < keyinfo->user_defined_key_parts ; key_part++,i++)
2141+
{
2142+
Field *field= key_part->field;
2143+
/*
2144+
If this field is part of the primary key and all keys contains
2145+
the primary key, then we can use any key to find this column
2146+
*/
2147+
if (field->key_length() == key_part->length &&
2148+
!(field->flags & BLOB_FLAG))
2149+
field->part_of_key= share->keys_in_use;
2150+
if (field->part_of_sortkey.is_set(primary_key))
2151+
field->part_of_sortkey= share->keys_in_use;
2152+
}
2153+
}
2154+
21352155
if (primary_key < MAX_KEY &&
21362156
(share->keys_in_use.is_set(primary_key)))
21372157
{

storage/rocksdb/ha_rocksdb.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4075,7 +4075,7 @@ bool ha_rocksdb::same_table(const ha_rocksdb& other) const
40754075
return m_tbl_def->base_tablename() == other.m_tbl_def->base_tablename();
40764076
}
40774077

4078-
#ifdef MARIAROCKS_NOT_YET
4078+
40794079
bool ha_rocksdb::init_with_fields()
40804080
{
40814081
uint pk= table_share->primary_key;
@@ -4090,7 +4090,7 @@ bool ha_rocksdb::init_with_fields()
40904090
cached_table_flags= table_flags();
40914091
return false; /* Ok */
40924092
}
4093-
#endif
4093+
40944094

40954095
/**
40964096
Convert record from table->record[0] form into a form that can be written
@@ -4884,6 +4884,7 @@ int ha_rocksdb::open(const char *name, int mode, uint test_if_locked)
48844884
DBUG_RETURN(err);
48854885
}
48864886

4887+
init_with_fields();
48874888
setup_field_converters();
48884889

48894890
info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);

storage/rocksdb/ha_rocksdb.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,9 @@ class ha_rocksdb: public my_core::handler
592592
HA_PARTIAL_COLUMN_READ |
593593
HA_TABLE_SCAN_ON_INDEX;
594594
}
595-
#ifdef MARIAROCKS_NOT_YET
595+
//#ifdef MARIAROCKS_NOT_YET
596596
bool init_with_fields() override;
597-
#endif
597+
//#endif
598598
/** @brief
599599
This is a bitmap of flags that indicates how the storage engine
600600
implements indexes. The current index flags are documented in

0 commit comments

Comments
 (0)