Bug #47432 | CREATE TABLE tbl_new SELECT * FROM tbl_exists; ignores indexes | ||
---|---|---|---|
Submitted: | 18 Sep 2009 9:45 | Modified: | 18 Sep 2009 10:02 |
Reporter: | Harald Reindl | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: General | Severity: | S3 (Non-critical) |
Version: | OS: | Any | |
Assigned to: | CPU Architecture: | Any |
[18 Sep 2009 9:45]
Harald Reindl
[18 Sep 2009 9:52]
Valeriy Kravchuk
This behavior is documented. See http://dev.mysql.com/doc/refman/5.1/en/create-table.html: "CREATE TABLE ... SELECT does not automatically create any indexes for you. This is done intentionally to make the statement as flexible as possible. If you want to have indexes in the created table, you should specify these before the SELECT statement: mysql> CREATE TABLE bar (UNIQUE (n)) SELECT n FROM foo;"
[18 Sep 2009 10:02]
Harald Reindl
I made the workaround creating all tables before i wrote the bugreport but this is clearly a bug for me because for complex tables it is much easier to drop indexes rather to add them after copy the table This can make really troubles if you do not see missing indexes and believe you have a 1:1 copy of the existing table Following example to copy the whole data of a website with new prefixes for make layout-changes, in the worst case you start working in the new page and realize much too late that new entries without page-id are created ________________________ use aume; drop table if exists aume2009_global_cache; drop table if exists aume2009_haupt; drop table if exists aume2009_locks; drop table if exists aume2009_meta; drop table if exists aume2009_newsletter; drop table if exists aume2009_newsletter_archiv; drop table if exists aume2009_produktionsmeldung; drop table if exists aume2009_search_index; drop table if exists aume2009_snippets; drop table if exists aume2009_stg_sub; drop table if exists aume2009_stg_sub2; drop table if exists aume2009_sub; drop table if exists aume2009_sub2; drop table if exists aume2009_user_group_permissions; drop table if exists aume2009_user_login; drop table if exists aume2009_user_modules; drop table if exists aume2009_user_online; drop table if exists aume2009_users; create table aume2009_global_cache select * from aume_global_cache; create table aume2009_haupt select * from aume_haupt; create table aume2009_locks select * from aume_locks; create table aume2009_meta select * from aume_meta; create table aume2009_newsletter select * from aume_newsletter; create table aume2009_newsletter_archiv select * from aume_newsletter_archiv; create table aume2009_produktionsmeldung select * from aume_produktionsmeldung; create table aume2009_search_index select * from aume_search_index; create table aume2009_snippets select * from aume_snippets; create table aume2009_stg_sub select * from aume_stg_sub; create table aume2009_stg_sub2 select * from aume_stg_sub2; create table aume2009_sub select * from aume_sub; create table aume2009_sub2 select * from aume_sub2; create table aume2009_user_group_permissions select * from aume_user_group_permissions; create table aume2009_user_login select * from aume_user_login; create table aume2009_user_modules select * from aume_user_modules; create table aume2009_user_online select * from aume_user_online; create table aume2009_users select * from aume_users;