From 2f93aa9e51559f1a681544c1e0b7be4706e3fe24 Mon Sep 17 00:00:00 2001 From: "monty@hundin.mysql.fi" <> Date: Wed, 29 Aug 2001 17:33:41 +0300 Subject: [PATCH] Test that all MERGE tables comes from the same database --- Docs/manual.texi | 40 ++++++++++++++++++++++++------- include/mysqld_error.h | 3 ++- mysql-test/t/merge.test | 6 ++++- sql/gen_lex_hash.cc | 2 +- sql/ha_myisammrg.cc | 6 ----- sql/share/czech/errmsg.txt | 1 + sql/share/danish/errmsg.txt | 1 + sql/share/dutch/errmsg.txt | 1 + sql/share/english/errmsg.txt | 1 + sql/share/estonian/errmsg.txt | 1 + sql/share/french/errmsg.txt | 1 + sql/share/german/errmsg.txt | 1 + sql/share/greek/errmsg.txt | 1 + sql/share/hungarian/errmsg.txt | 1 + sql/share/italian/errmsg.txt | 1 + sql/share/japanese/errmsg.txt | 1 + sql/share/korean/errmsg.txt | 1 + sql/share/norwegian-ny/errmsg.txt | 1 + sql/share/norwegian/errmsg.txt | 1 + sql/share/polish/errmsg.txt | 1 + sql/share/portuguese/errmsg.txt | 1 + sql/share/romanian/errmsg.txt | 1 + sql/share/russian/errmsg.txt | 1 + sql/share/slovak/errmsg.txt | 1 + sql/share/spanish/errmsg.txt | 1 + sql/share/swedish/errmsg.txt | 1 + sql/sql_parse.cc | 12 ++++++++-- 27 files changed, 71 insertions(+), 19 deletions(-) diff --git a/Docs/manual.texi b/Docs/manual.texi index 6e77f0110cd..a54b3327e17 100644 --- a/Docs/manual.texi +++ b/Docs/manual.texi @@ -4502,6 +4502,13 @@ Minimum respective maximum possible @code{double} value. @item @code{LIMIT} on negative numbers are treated as big positive numbers. +@item +If you use @code{ALTER TABLE} to first add an @code{UNIQUE} index to a +table used in a @code{MERGE} table and then use @code{ALTER TABLE} to +add a normal index on the @code{MERGE} table, the key order will be +different for the tables if there was an old not-unique key in the +table. This is because @code{ALTER TABLE} puts @code{UNIQUE} keys before +normal keys to be able to detect duplicate keys as early as possible. @end itemize The following are known bugs in earlier versions of MySQL: @@ -11688,9 +11695,9 @@ work: @example CC="cc -pthread" -CFLAGS="-O4 -ansi_alias -ansi_args -fast -inline speed -speculate all -arch host" +CFLAGS="-O4 -ansi_alias -ansi_args -fast -inline speed all -arch host" CXX="cxx -pthread" -CXXFLAGS="-O4 -ansi_alias -ansi_args -fast -inline speed -speculate all -arch host" +CXXFLAGS="-O4 -ansi_alias -ansi_args -fast -inline speed all -arch host" export CC CFLAGS CXX CXXFLAGS ./configure \ --prefix=/usr/local/mysql \ @@ -34149,6 +34156,12 @@ index exists, it drops the first @code{UNIQUE} index in the table. (MySQL marks the first @code{UNIQUE} key as the @code{PRIMARY KEY} if no @code{PRIMARY KEY} was specified explicitly.) +@findex UNIQUE +@findex PRIMARY KEY +If you add a @code{UNIQUE INDEX} or @code{PRIMARY KEY} to a table, this +is stored before any not @code[UNIQUE} index so that MySQL can detect +duplicate keys as early as possible. + @findex ORDER BY @item @code{ORDER BY} allows you to create the new table with the rows in a @@ -35558,14 +35571,15 @@ mapped tables. (We plan to fix this in 4.0). With identical tables we mean that all tables are created with identical column and key information. You can't put a MERGE over tables where the -columns are packed differently or doesn't have exactly the same columns. -Some of the tables can however be compressed with @code{myisampack}. -@xref{myisampack}. +columns are packed differently, doesn't have exactly the same columns or +have the keys in different order. Some of the tables can however be +compressed with @code{myisampack}. @xref{myisampack}. When you create a @code{MERGE} table, you will get a @code{.frm} table definition file and a @code{.MRG} table list file. The @code{.MRG} just contains a list of the index files (@code{.MYI} files) that should -be used as one. +be used as one. All used tables must be in the same database as the +@code{MERGE} table itself. For the moment you need to have @code{SELECT}, @code{UPDATE}, and @code{DELETE} privileges on the tables you map to a @code{MERGE} table. @@ -35691,7 +35705,6 @@ Change the @code{.MRG} file and issue a @code{FLUSH TABLE} on the read the new definition file. @end itemize - @node ISAM, HEAP, MERGE, Table types @section ISAM Tables @@ -46683,15 +46696,26 @@ not yet 100% confident in this code. @appendixsubsec Changes in release 3.23.42 @itemize @bullet @item +Enforce that all tables in a @code{MERGE} table comes from the same +database. +@item +Fixed bug with @code{LOAD DATA INFILE} and transactional tables. +@item +Fix bug when using @code{INSERT DELAYED} with wrong column definition. +@item Fixed bug in @code{InnoDB} and @code{AUTO_INCREMENT} columns. @item +Fixed critical bug in @code{InnoDB} and @code{BLOB}'s. If one has used +@code{BLOB}'s larger than 8K in an @code{InnoDB} table one must dump +the table with @code{mysqldump}, drop it and restore it from the dump. +@item Applied large patch for OS/2 from Yuri Dario. @item Fixed problem with InnoDB when one could get the error @code{Can't execute the given command...} even when one didn't have an active transaction. @item -Applied some fixes for Gemini. +Applied some minor fixes that concerns Gemini. @item Use real arithmetic operations even in integer context if not all arguments are integers. (Fixes uncommon bug in some integer diff --git a/include/mysqld_error.h b/include/mysqld_error.h index 758c74fc122..08e621f4a2a 100644 --- a/include/mysqld_error.h +++ b/include/mysqld_error.h @@ -212,4 +212,5 @@ #define ER_CREATE_DB_WITH_READ_LOCK 1209 #define ER_WRONG_ARGUMENTS 1210 #define ER_NO_PERMISSON_TO_CREATE_USER 1211 -#define ER_ERROR_MESSAGES 212 +#define ER_UNION_TABLES_IN_DIFFERENT_DIR 1212 +#define ER_ERROR_MESSAGES 213 diff --git a/mysql-test/t/merge.test b/mysql-test/t/merge.test index 59da525990c..6820242d562 100644 --- a/mysql-test/t/merge.test +++ b/mysql-test/t/merge.test @@ -35,9 +35,13 @@ show create table t3; # The following should give errors create table t4 (a int not null, b char(10), key(a)) type=MERGE UNION=(t1,t2); +--error 1016 +select * from t4; +--error 1212 +create table t5 (a int not null, b char(10), key(a)) type=MERGE UNION=(test.t1,test_2.t2); # Because of windows, it's important that we drop the merge tables first! -drop table if exists t4,t3,t1,t2; +drop table if exists t5,t4,t3,t1,t2; create table t1 (c char(10)) type=myisam; create table t2 (c char(10)) type=myisam; diff --git a/sql/gen_lex_hash.cc b/sql/gen_lex_hash.cc index d55197a8b60..e05fdafcbc4 100644 --- a/sql/gen_lex_hash.cc +++ b/sql/gen_lex_hash.cc @@ -472,7 +472,7 @@ int main(int argc,char **argv) int error; MY_INIT(argv[0]); - start_value=4597269L; best_t1=6001982L; best_t2=5063828L; best_type=4; /* mode=4513 add=8 type: 0 */ + start_value=6130115L; best_t1=3632784L; best_t2=86437L; best_type=3; /* mode=4229 add=2 type: 0 */ if (get_options(argc,(char **) argv)) exit(1); diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc index 866fd1e69f9..1feaa4e5d66 100644 --- a/sql/ha_myisammrg.cc +++ b/sql/ha_myisammrg.cc @@ -86,7 +86,6 @@ int ha_myisammrg::delete_row(const byte * buf) int ha_myisammrg::index_read(byte * buf, const byte * key, uint key_len, enum ha_rkey_function find_flag) { -// return (my_errno=HA_ERR_WRONG_COMMAND); statistic_increment(ha_read_key_count,&LOCK_status); int error=myrg_rkey(file,buf,active_index, key, key_len, find_flag); table->status=error ? STATUS_NOT_FOUND: 0; @@ -96,7 +95,6 @@ int ha_myisammrg::index_read(byte * buf, const byte * key, int ha_myisammrg::index_read_idx(byte * buf, uint index, const byte * key, uint key_len, enum ha_rkey_function find_flag) { -// return (my_errno=HA_ERR_WRONG_COMMAND); statistic_increment(ha_read_key_count,&LOCK_status); int error=myrg_rkey(file,buf,index, key, key_len, find_flag); table->status=error ? STATUS_NOT_FOUND: 0; @@ -105,7 +103,6 @@ int ha_myisammrg::index_read_idx(byte * buf, uint index, const byte * key, int ha_myisammrg::index_next(byte * buf) { -// return (my_errno=HA_ERR_WRONG_COMMAND); statistic_increment(ha_read_next_count,&LOCK_status); int error=myrg_rnext(file,buf,active_index); table->status=error ? STATUS_NOT_FOUND: 0; @@ -114,7 +111,6 @@ int ha_myisammrg::index_next(byte * buf) int ha_myisammrg::index_prev(byte * buf) { -// return (my_errno=HA_ERR_WRONG_COMMAND); statistic_increment(ha_read_prev_count,&LOCK_status); int error=myrg_rprev(file,buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; @@ -123,7 +119,6 @@ int ha_myisammrg::index_prev(byte * buf) int ha_myisammrg::index_first(byte * buf) { -// return (my_errno=HA_ERR_WRONG_COMMAND); statistic_increment(ha_read_first_count,&LOCK_status); int error=myrg_rfirst(file, buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; @@ -132,7 +127,6 @@ int ha_myisammrg::index_first(byte * buf) int ha_myisammrg::index_last(byte * buf) { -// return (my_errno=HA_ERR_WRONG_COMMAND); statistic_increment(ha_read_last_count,&LOCK_status); int error=myrg_rlast(file, buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; diff --git a/sql/share/czech/errmsg.txt b/sql/share/czech/errmsg.txt index f67496da923..1ca2aa9b02b 100644 --- a/sql/share/czech/errmsg.txt +++ b/sql/share/czech/errmsg.txt @@ -222,3 +222,4 @@ "CREATE DATABASE not allowed while thread is holding global read lock", "Wrong arguments to %s", "%-.32s@%-.64s is not allowed to create new users", +"Incorrect table definition; All MERGE tables must be in the same database", diff --git a/sql/share/danish/errmsg.txt b/sql/share/danish/errmsg.txt index 34c3d8ed95d..e6c828625eb 100644 --- a/sql/share/danish/errmsg.txt +++ b/sql/share/danish/errmsg.txt @@ -216,3 +216,4 @@ "CREATE DATABASE er ikke tilladt mens en tråd holder på globalt read lock", "Wrong arguments to %s", "%-.32s@%-.64s is not allowed to create new users", +"Incorrect table definition; All MERGE tables must be in the same database", diff --git a/sql/share/dutch/errmsg.txt b/sql/share/dutch/errmsg.txt index b4573a551dc..abaa475402e 100644 --- a/sql/share/dutch/errmsg.txt +++ b/sql/share/dutch/errmsg.txt @@ -217,3 +217,4 @@ "CREATE DATABASE niet toegestaan terwijl thread een globale 'read lock' bezit", "Foutieve parameters voor %s", "%-.32s@%-.64s is not allowed to create new users", +"Incorrect table definition; All MERGE tables must be in the same database", diff --git a/sql/share/english/errmsg.txt b/sql/share/english/errmsg.txt index 80b99c58940..7fc0928d67d 100644 --- a/sql/share/english/errmsg.txt +++ b/sql/share/english/errmsg.txt @@ -213,3 +213,4 @@ "CREATE DATABASE not allowed while thread is holding global read lock", "Wrong arguments to %s", "%-.32s@%-.64s is not allowed to create new users", +"Incorrect table definition; All MERGE tables must be in the same database", diff --git a/sql/share/estonian/errmsg.txt b/sql/share/estonian/errmsg.txt index 59a8b156ab2..d9c98fa919d 100644 --- a/sql/share/estonian/errmsg.txt +++ b/sql/share/estonian/errmsg.txt @@ -217,3 +217,4 @@ "CREATE DATABASE not allowed while thread is holding global read lock", "Wrong arguments to %s", "%-.32s@%-.64s is not allowed to create new users", +"Incorrect table definition; All MERGE tables must be in the same database", diff --git a/sql/share/french/errmsg.txt b/sql/share/french/errmsg.txt index 98902e847b9..6dc6f150d57 100644 --- a/sql/share/french/errmsg.txt +++ b/sql/share/french/errmsg.txt @@ -213,3 +213,4 @@ "CREATE DATABASE not allowed while thread is holding global read lock", "Wrong arguments to %s", "%-.32s@%-.64s is not allowed to create new users", +"Incorrect table definition; All MERGE tables must be in the same database", diff --git a/sql/share/german/errmsg.txt b/sql/share/german/errmsg.txt index 1d9e770ea8d..262390d42ea 100644 --- a/sql/share/german/errmsg.txt +++ b/sql/share/german/errmsg.txt @@ -216,3 +216,4 @@ "CREATE DATABASE not allowed while thread is holding global read lock", "Wrong arguments to %s", "%-.32s@%-.64s is not allowed to create new users", +"Incorrect table definition; All MERGE tables must be in the same database", diff --git a/sql/share/greek/errmsg.txt b/sql/share/greek/errmsg.txt index f879c281422..146f196852b 100644 --- a/sql/share/greek/errmsg.txt +++ b/sql/share/greek/errmsg.txt @@ -213,3 +213,4 @@ "CREATE DATABASE not allowed while thread is holding global read lock", "Wrong arguments to %s", "%-.32s@%-.64s is not allowed to create new users", +"Incorrect table definition; All MERGE tables must be in the same database", diff --git a/sql/share/hungarian/errmsg.txt b/sql/share/hungarian/errmsg.txt index 303032d73b2..1d76fd1d898 100644 --- a/sql/share/hungarian/errmsg.txt +++ b/sql/share/hungarian/errmsg.txt @@ -215,3 +215,4 @@ "CREATE DATABASE not allowed while thread is holding global read lock", "Wrong arguments to %s", "%-.32s@%-.64s is not allowed to create new users", +"Incorrect table definition; All MERGE tables must be in the same database", diff --git a/sql/share/italian/errmsg.txt b/sql/share/italian/errmsg.txt index c927eceb163..79e8c8aed8b 100644 --- a/sql/share/italian/errmsg.txt +++ b/sql/share/italian/errmsg.txt @@ -213,3 +213,4 @@ "CREATE DATABASE not allowed while thread is holding global read lock", "Wrong arguments to %s", "%-.32s@%-.64s is not allowed to create new users", +"Incorrect table definition; All MERGE tables must be in the same database", diff --git a/sql/share/japanese/errmsg.txt b/sql/share/japanese/errmsg.txt index a177fcf81a8..2971882d431 100644 --- a/sql/share/japanese/errmsg.txt +++ b/sql/share/japanese/errmsg.txt @@ -215,3 +215,4 @@ "CREATE DATABASE not allowed while thread is holding global read lock", "Wrong arguments to %s", "%-.32s@%-.64s is not allowed to create new users", +"Incorrect table definition; All MERGE tables must be in the same database", diff --git a/sql/share/korean/errmsg.txt b/sql/share/korean/errmsg.txt index 5c12cbf7d42..7fbc60b8953 100644 --- a/sql/share/korean/errmsg.txt +++ b/sql/share/korean/errmsg.txt @@ -213,3 +213,4 @@ "CREATE DATABASE not allowed while thread is holding global read lock", "Wrong arguments to %s", "%-.32s@%-.64s is not allowed to create new users", +"Incorrect table definition; All MERGE tables must be in the same database", diff --git a/sql/share/norwegian-ny/errmsg.txt b/sql/share/norwegian-ny/errmsg.txt index 05562e675bb..9fb3f5f5666 100644 --- a/sql/share/norwegian-ny/errmsg.txt +++ b/sql/share/norwegian-ny/errmsg.txt @@ -215,3 +215,4 @@ "CREATE DATABASE not allowed while thread is holding global read lock", "Wrong arguments to %s", "%-.32s@%-.64s is not allowed to create new users", +"Incorrect table definition; All MERGE tables must be in the same database", diff --git a/sql/share/norwegian/errmsg.txt b/sql/share/norwegian/errmsg.txt index 8d973a57137..cc04859d99d 100644 --- a/sql/share/norwegian/errmsg.txt +++ b/sql/share/norwegian/errmsg.txt @@ -215,3 +215,4 @@ "CREATE DATABASE not allowed while thread is holding global read lock", "Wrong arguments to %s", "%-.32s@%-.64s is not allowed to create new users", +"Incorrect table definition; All MERGE tables must be in the same database", diff --git a/sql/share/polish/errmsg.txt b/sql/share/polish/errmsg.txt index 705eb7f86ef..989c1f7f45d 100644 --- a/sql/share/polish/errmsg.txt +++ b/sql/share/polish/errmsg.txt @@ -217,3 +217,4 @@ "CREATE DATABASE not allowed while thread is holding global read lock", "Wrong arguments to %s", "%-.32s@%-.64s is not allowed to create new users", +"Incorrect table definition; All MERGE tables must be in the same database", diff --git a/sql/share/portuguese/errmsg.txt b/sql/share/portuguese/errmsg.txt index 9bb32287543..82670f503b0 100644 --- a/sql/share/portuguese/errmsg.txt +++ b/sql/share/portuguese/errmsg.txt @@ -213,3 +213,4 @@ "CREATE DATABASE não permitido enquanto uma 'thread' está mantendo um travamento global de leitura", "Argumentos errados para %s", "Não é permitido a %-.32s@%-.64s criar novos usuários", +"Incorrect table definition; All MERGE tables must be in the same database", diff --git a/sql/share/romanian/errmsg.txt b/sql/share/romanian/errmsg.txt index 2364bbb6d7d..ba214e540e6 100644 --- a/sql/share/romanian/errmsg.txt +++ b/sql/share/romanian/errmsg.txt @@ -217,3 +217,4 @@ "CREATE DATABASE not allowed while thread is holding global read lock", "Wrong arguments to %s", "%-.32s@%-.64s is not allowed to create new users", +"Incorrect table definition; All MERGE tables must be in the same database", diff --git a/sql/share/russian/errmsg.txt b/sql/share/russian/errmsg.txt index 0d778d67f11..94889100847 100644 --- a/sql/share/russian/errmsg.txt +++ b/sql/share/russian/errmsg.txt @@ -216,3 +216,4 @@ "CREATE DATABASE not allowed while thread is holding global read lock", "Wrong arguments to %s", "%-.32s@%-.64s is not allowed to create new users", +"Incorrect table definition; All MERGE tables must be in the same database", diff --git a/sql/share/slovak/errmsg.txt b/sql/share/slovak/errmsg.txt index e990e00722b..652f50c77c8 100644 --- a/sql/share/slovak/errmsg.txt +++ b/sql/share/slovak/errmsg.txt @@ -221,3 +221,4 @@ "CREATE DATABASE not allowed while thread is holding global read lock", "Wrong arguments to %s", "%-.32s@%-.64s is not allowed to create new users", +"Incorrect table definition; All MERGE tables must be in the same database", diff --git a/sql/share/spanish/errmsg.txt b/sql/share/spanish/errmsg.txt index 35788a72935..271b362f63f 100644 --- a/sql/share/spanish/errmsg.txt +++ b/sql/share/spanish/errmsg.txt @@ -214,3 +214,4 @@ "CREATE DATABASE no permitido mientras un thread está ejerciendo un bloqueo de lectura global", "Wrong arguments to %s", "%-.32s@%-.64s is not allowed to create new users", +"Incorrect table definition; All MERGE tables must be in the same database", diff --git a/sql/share/swedish/errmsg.txt b/sql/share/swedish/errmsg.txt index 5914ea31188..1eb3e9db1e7 100644 --- a/sql/share/swedish/errmsg.txt +++ b/sql/share/swedish/errmsg.txt @@ -213,3 +213,4 @@ "CREATE DATABASE är inte tillåtet när man har ett globalt läs-lås", "Felaktiga argument till %s", "%-.32s@%-.64s har inte rättigheter att skapa nya användare", +"Felaktig tabell definition: Alla tabeller i en MERGE tabell måste vara i samma databas", diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 2e5333925e7..99fc0fc8fbf 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2178,10 +2178,18 @@ static bool check_merge_table_access(THD *thd, char *db, int error=0; if (table_list) { - /* Force all tables to use the current database */ + /* Check that all tables use the current database */ TABLE_LIST *tmp; for (tmp=table_list; tmp ; tmp=tmp->next) - tmp->db=db; + { + if (!tmp->db || !tmp->db[0]) + tmp->db=db; + else if (!strcmp(tmp->db,db)) + { + send_error(&thd->net,ER_UNION_TABLES_IN_DIFFERENT_DIR); + return 1; + } + } error=check_table_access(thd, SELECT_ACL | UPDATE_ACL | DELETE_ACL, table_list); }