Skip to content

Commit

Permalink
cleanup: remove HA_WANTS_PRIMARY_KEY as redundant
Browse files Browse the repository at this point in the history
We don't have many bits left, no need to add another InnoDB-specific flag.
Instead, we say that HA_REQUIRE_PRIMARY_KEY does not apply to SEQUENCE.
Meaning, if the engine declares HA_CAN_TABLES_WITHOUT_ROLLBACK (required
for SEQUENCE) it *must* support tables without a primary key.
  • Loading branch information
vuvova committed Nov 20, 2018
1 parent 5aaee37 commit 649465d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
4 changes: 0 additions & 4 deletions sql/ha_partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -1040,10 +1040,6 @@ class ha_partition :public handler
with hidden primary key)
(No handler has this limitation currently)
HA_WANTS_PRIMARY_KEY:
Can't define a table without primary key except sequences
(Only InnoDB has this when using innodb_force_primary_key == ON)
HA_STATS_RECORDS_IS_EXACT:
Does the counter of records after the info call specify an exact
value or not. If it does this flag is set.
Expand Down
10 changes: 7 additions & 3 deletions sql/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ enum enum_alter_inplace_result {
#define HA_NO_BLOBS (1ULL << 9) /* Doesn't support blobs */
#define HA_CAN_INDEX_BLOBS (1ULL << 10)
#define HA_AUTO_PART_KEY (1ULL << 11) /* auto-increment in multi-part key */
#define HA_REQUIRE_PRIMARY_KEY (1ULL << 12) /* .. and can't create a hidden one */
/*
The engine requires every table to have a user-specified PRIMARY KEY.
Do not set the flag if the engine can generate a hidden primary key internally.
This flag is ignored if a SEQUENCE is created (which, in turn, needs
HA_CAN_TABLES_WITHOUT_ROLLBACK flag)
*/
#define HA_REQUIRE_PRIMARY_KEY (1ULL << 12)
#define HA_STATS_RECORDS_IS_EXACT (1ULL << 13) /* stats.records is exact */
/*
INSERT_DELAYED only works with handlers that uses MySQL internal table
Expand Down Expand Up @@ -301,8 +307,6 @@ enum enum_alter_inplace_result {
/* calling cmp_ref() on the engine is expensive */
#define HA_CMP_REF_IS_EXPENSIVE (1ULL << 54)

/* Engine wants primary keys for everything except sequences */
#define HA_WANTS_PRIMARY_KEY (1ULL << 55)

/* bits in index_flags(index_number) for what you can do with index */
#define HA_READ_NEXT 1 /* TODO really use this flag */
Expand Down
6 changes: 2 additions & 4 deletions sql/sql_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4133,10 +4133,8 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
key_info++;
}

if (!unique_key && !primary_key &&
((file->ha_table_flags() & HA_REQUIRE_PRIMARY_KEY) ||
((file->ha_table_flags() & HA_WANTS_PRIMARY_KEY) &&
!create_info->sequence)))
if (!unique_key && !primary_key && !create_info->sequence &&
(file->ha_table_flags() & HA_REQUIRE_PRIMARY_KEY))
{
my_message(ER_REQUIRES_PRIMARY_KEY, ER_THD(thd, ER_REQUIRES_PRIMARY_KEY),
MYF(0));
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2913,7 +2913,7 @@ ha_innobase::ha_innobase(
| HA_CAN_RTREEKEYS
| HA_CAN_TABLES_WITHOUT_ROLLBACK
| HA_CONCURRENT_OPTIMIZE
| (srv_force_primary_key ? HA_WANTS_PRIMARY_KEY : 0)
| (srv_force_primary_key ? HA_REQUIRE_PRIMARY_KEY : 0)
),
m_start_of_scan(),
m_mysql_has_locked()
Expand Down

0 comments on commit 649465d

Please sign in to comment.