Chris,
I suppose that with your change, the MySQL server goes ahead with the
alter in an offline fashion. If so, then this looks good to me.
OK to push.
Christopher Powers wrote:
> #At file:///home/cpowers/work/dev/dev-13/mysql/
>
> 2922 Christopher Powers 2008-12-01
> Bug#40994, "Regression: can't create unique index on NOT NULL columns if engine
> is falcon"
>
> The MySQL server interprets unique indexes on NOT NULL columns as a primary
> key.
> Falcon online add/drop index does not yet support primary keys.
> added:
> mysql-test/suite/falcon/r/falcon_bug_40994.result
> mysql-test/suite/falcon/t/falcon_bug_40994.test
> modified:
> storage/falcon/ha_falcon.cpp
>
> per-file messages:
> mysql-test/suite/falcon/r/falcon_bug_40994.result
> Result file for Bug#40994 testcase
> mysql-test/suite/falcon/t/falcon_bug_40994.test
> New testcase, Bug#40994
> storage/falcon/ha_falcon.cpp
> If new index is a primary key, create the index offline.
> === added file 'mysql-test/suite/falcon/r/falcon_bug_40994.result'
> --- a/mysql-test/suite/falcon/r/falcon_bug_40994.result 1970-01-01 00:00:00 +0000
> +++ b/mysql-test/suite/falcon/r/falcon_bug_40994.result 2008-12-01 22:18:34 +0000
> @@ -0,0 +1,19 @@
> +*** Bug #40994 ***
> +SET @@storage_engine = 'Falcon';
> +DROP TABLE IF EXISTS t1;
> +CREATE TABLE t1 (a int(11) NOT NULL ) ENGINE=Falcon DEFAULT CHARSET=latin1;
> +SHOW CREATE TABLE t1;
> +Table Create Table
> +t1 CREATE TABLE `t1` (
> + `a` int(11) NOT NULL
> +) ENGINE=Falcon DEFAULT CHARSET=latin1
> +INSERT INTO t1 VALUES (1), (2), (3);
> +CREATE UNIQUE INDEX i1 ON t1 (a);
> +INSERT INTO t1 VALUES (4), (5), (6);
> +DESCRIBE t1;
> +Field Type Null Key Default Extra
> +a int(11) NO PRI NULL
> +SELECT count(*) FROM t1;
> +count(*)
> +6
> +DROP TABLE t1;
>
> === added file 'mysql-test/suite/falcon/t/falcon_bug_40994.test'
> --- a/mysql-test/suite/falcon/t/falcon_bug_40994.test 1970-01-01 00:00:00 +0000
> +++ b/mysql-test/suite/falcon/t/falcon_bug_40994.test 2008-12-01 22:18:34 +0000
> @@ -0,0 +1,36 @@
> +--source include/have_falcon.inc
> +#
> +# Bug #40994: Falcon: can't create unique index on NOT NULL column if engine is
> falcon
> +#
> +--echo *** Bug #40994 ***
> +
> +# ----------------------------------------------------- #
> +# --- Initialisation --- #
> +# ----------------------------------------------------- #
> +let $engine = 'Falcon';
> +eval SET @@storage_engine = $engine;
> +
> +--disable_warnings
> +DROP TABLE IF EXISTS t1;
> +--enable_warnings
> +
> +CREATE TABLE t1 (a int(11) NOT NULL ) ENGINE=Falcon DEFAULT CHARSET=latin1;
> +SHOW CREATE TABLE t1;
> +
> +# ----------------------------------------------------- #
> +# --- Test --- #
> +# ----------------------------------------------------- #
> +INSERT INTO t1 VALUES (1), (2), (3);
> +CREATE UNIQUE INDEX i1 ON t1 (a);
> +INSERT INTO t1 VALUES (4), (5), (6);
> +
> +# ----------------------------------------------------- #
> +# --- Check --- #
> +# ----------------------------------------------------- #
> +DESCRIBE t1;
> +SELECT count(*) FROM t1;
> +
> +# ----------------------------------------------------- #
> +# --- Final cleanup --- #
> +# ----------------------------------------------------- #
> +DROP TABLE t1;
>
> === modified file 'storage/falcon/ha_falcon.cpp'
> --- a/storage/falcon/ha_falcon.cpp 2008-11-25 13:38:06 +0000
> +++ b/storage/falcon/ha_falcon.cpp 2008-12-01 22:18:34 +0000
> @@ -2201,10 +2201,6 @@ int StorageInterface::check_if_supported
> if (tempTable || (*alter_flags & notSupported).is_set())
> DBUG_RETURN(HA_ALTER_NOT_SUPPORTED);
>
> - // TODO:
> - // 1. Check for supported ALTER combinations
> - // 2. Check for explicit default (altered_table->s->default_values)
> -
> if (alter_flags->is_set(HA_ADD_COLUMN))
> {
> Field *field = NULL;
> @@ -2227,6 +2223,33 @@ int StorageInterface::check_if_supported
> }
> }
>
> + if (alter_flags->is_set(HA_ADD_INDEX) ||
> alter_flags->is_set(HA_ADD_UNIQUE_INDEX)
> + || alter_flags->is_set(HA_DROP_INDEX) ||
> alter_flags->is_set(HA_DROP_UNIQUE_INDEX))
> + {
> + for (unsigned int n = 0; n < altered_table->s->keys; n++)
> + {
> + KEY *key = altered_table->key_info + n;
> + KEY *tableEnd = table->key_info + table->s->keys;
> + KEY *tableKey;
> +
> + // Determine if this is a new index
> +
> + for (tableKey = table->key_info; tableKey < tableEnd; tableKey++)
> + if (!strcmp(tableKey->name, key->name))
> + break;
> +
> + // Unique, non-null keys are interpreted as primary keys.
> + // Online add/drop primary keys not yet supported.
> +
> + if (tableKey >= tableEnd)
> + if (n == altered_table->s->primary_key)
> + {
> + DBUG_PRINT("info",("Online add/drop primary key not supported"));
> + DBUG_RETURN(HA_ALTER_NOT_SUPPORTED);
> + }
> + }
> + }
> +
> DBUG_RETURN(HA_ALTER_SUPPORTED_NO_LOCK);
> }
>
>
>