diff options
Diffstat (limited to 'sql')
-rw-r--r-- | sql/sql_update.cc | 30 | ||||
-rw-r--r-- | sql/table.h | 4 |
2 files changed, 22 insertions, 12 deletions
diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 59356540201..90c4697d663 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -1071,17 +1071,27 @@ bool unsafe_key_update(TABLE_LIST *leaves, table_map tables_for_update) return true; } - if (primkey_clustered && - (bitmap_is_set(table1->write_set, table1->s->primary_key) || - bitmap_is_set(table2->write_set, table2->s->primary_key))) + if (primkey_clustered) { - // Clustered primary key is updated - my_error(ER_MULTI_UPDATE_KEY_CONFLICT, MYF(0), - tl->belong_to_view ? tl->belong_to_view->alias - : tl->alias, - tl2->belong_to_view ? tl2->belong_to_view->alias - : tl2->alias); - return true; + // The primary key can cover multiple columns + KEY key_info= table1->key_info[table1->s->primary_key]; + KEY_PART_INFO *key_part= key_info.key_part; + KEY_PART_INFO *key_part_end= key_part + key_info.key_parts; + + for (;key_part != key_part_end; ++key_part) + { + if (bitmap_is_set(table1->write_set, key_part->fieldnr-1) || + bitmap_is_set(table2->write_set, key_part->fieldnr-1)) + { + // Clustered primary key is updated + my_error(ER_MULTI_UPDATE_KEY_CONFLICT, MYF(0), + tl->belong_to_view ? tl->belong_to_view->alias + : tl->alias, + tl2->belong_to_view ? tl2->belong_to_view->alias + : tl2->alias); + return true; + } + } } } } diff --git a/sql/table.h b/sql/table.h index afdf4f7baa9..81b42c5b013 100644 --- a/sql/table.h +++ b/sql/table.h @@ -627,8 +627,8 @@ struct TABLE_SHARE uint db_options_in_use; /* Options in use */ uint db_record_offset; /* if HA_REC_IN_SEQ */ uint rowid_field_offset; /* Field_nr +1 to rowid field */ - /* Index of auto-updated TIMESTAMP field in field array */ - uint primary_key; + /* Primary key index number, used in TABLE::key_info[] */ + uint primary_key; uint next_number_index; /* autoincrement key number */ uint next_number_key_offset; /* autoinc keypart offset in a key */ uint next_number_keypart; /* autoinc keypart number in a key */ |