summaryrefslogtreecommitdiff
path: root/sql/handler.h
diff options
context:
space:
mode:
Diffstat (limited to 'sql/handler.h')
-rw-r--r--sql/handler.h37
1 files changed, 29 insertions, 8 deletions
diff --git a/sql/handler.h b/sql/handler.h
index 9d159771097..e1a3409f1c9 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -4029,6 +4029,7 @@ public:
virtual void set_part_info(partition_info *part_info) {return;}
virtual void return_record_by_parent() { return; }
+ /* Information about index. Both index and part starts from 0 */
virtual ulong index_flags(uint idx, uint part, bool all_parts) const =0;
uint max_record_length() const
@@ -4168,30 +4169,52 @@ public:
}
/*
- Check if the primary key (if there is one) is a clustered and a
- reference key. This means:
+ Check if the key is a clustering key
- Data is stored together with the primary key (no secondary lookup
needed to find the row data). The optimizer uses this to find out
the cost of fetching data.
- - The primary key is part of each secondary key and is used
+
+ Note that in many cases a clustered key is also a reference key.
+ This means that:
+
+ - The key is part of each secondary key and is used
to find the row data in the primary index when reading trough
secondary indexes.
- When doing a HA_KEYREAD_ONLY we get also all the primary key parts
into the row. This is critical property used by index_merge.
All the above is usually true for engines that store the row
- data in the primary key index (e.g. in a b-tree), and use the primary
+ data in the primary key index (e.g. in a b-tree), and use the key
key value as a position(). InnoDB is an example of such an engine.
- For such a clustered primary key, the following should also hold:
+ For a clustered (primary) key, the following should also hold:
index_flags() should contain HA_CLUSTERED_INDEX
table_flags() should contain HA_TABLE_SCAN_ON_INDEX
+ For a reference key the following should also hold:
+ table_flags() should contain HA_PRIMARY_KEY_IS_READ_INDEX.
+
@retval TRUE yes
@retval FALSE No.
*/
- virtual bool primary_key_is_clustered() { return FALSE; }
+
+ /* The following code is for primary keys */
+ bool pk_is_clustering_key(uint index) const
+ {
+ /*
+ We have to check for MAX_INDEX as table->s->primary_key can be
+ MAX_KEY in the case where there is no primary key.
+ */
+ return index != MAX_KEY && is_clustering_key(index);
+ }
+ /* Same as before but for other keys, in which case we can skip the check */
+ bool is_clustering_key(uint index) const
+ {
+ DBUG_ASSERT(index != MAX_KEY);
+ return (index_flags(index, 0, 1) & HA_CLUSTERED_INDEX);
+ }
+
virtual int cmp_ref(const uchar *ref1, const uchar *ref2)
{
return memcmp(ref1, ref2, ref_length);
@@ -4921,8 +4944,6 @@ public:
virtual void update_partition(uint part_id)
{}
- virtual bool is_clustering_key(uint index) { return false; }
-
/**
Some engines can perform column type conversion with ALGORITHM=INPLACE.
These functions check for such possibility.