summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <brian@zim.(none)>2006-01-10 22:54:34 -0800
committerunknown <brian@zim.(none)>2006-01-10 22:54:34 -0800
commita9d9054a10b5f7cb6ed288871fd4922ba8387380 (patch)
treeaad87c148f4c6253ee2360c95716cb028bb23652
parent2c0f53d69ceba4f3db98afba47bfb73b3b83525d (diff)
downloadmariadb-git-a9d9054a10b5f7cb6ed288871fd4922ba8387380.tar.gz
Added support for CREATE TABLE AUTO_INCREMENT and added more tests. Also non-unique index scans of autoincrement not function.
mysql-test/r/archive.result: New Result file. mysql-test/t/archive.test: New tests. Modifies old style 0 to NULL. sql/ha_archive.cc: Added support for scanning non unique indexes. Added support for the AUTO_INCREMENT bit for CREATE TABLE sql/ha_archive.h: Added variables for continueing scans of index_next
-rw-r--r--mysql-test/r/archive.result87
-rw-r--r--mysql-test/t/archive.test60
-rw-r--r--sql/ha_archive.cc40
-rw-r--r--sql/ha_archive.h5
4 files changed, 157 insertions, 35 deletions
diff --git a/mysql-test/r/archive.result b/mysql-test/r/archive.result
index d8378a1a2da..4f38ae0228c 100644
--- a/mysql-test/r/archive.result
+++ b/mysql-test/r/archive.result
@@ -12351,18 +12351,18 @@ CREATE TABLE `t5` (
b char(12),
PRIMARY KEY (`a`)
) ENGINE=ARCHIVE DEFAULT CHARSET=latin1;
-INSERT INTO t5 VALUES (0, "foo");
-INSERT INTO t5 VALUES (0, "foo");
-INSERT INTO t5 VALUES (0, "foo");
-INSERT INTO t5 VALUES (0, "foo");
-INSERT INTO t5 VALUES (0, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
INSERT INTO t5 VALUES (32, "foo");
INSERT INTO t5 VALUES (23, "foo");
-INSERT INTO t5 VALUES (0, "foo");
-INSERT INTO t5 VALUES (0, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
INSERT INTO t5 VALUES (3, "foo");
ERROR 23000: Can't write; duplicate key in table 't5'
-INSERT INTO t5 VALUES (0, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
SELECT * FROM t5;
a b
1 foo
@@ -12375,23 +12375,78 @@ a b
33 foo
34 foo
35 foo
+SELECT * FROM t5 WHERE a=3;
+a b
+3 foo
+DROP TABLE t5;
+CREATE TABLE `t5` (
+`a` int(11) NOT NULL auto_increment,
+b char(12),
+KEY (`a`)
+) ENGINE=ARCHIVE DEFAULT CHARSET=latin1 AUTO_INCREMENT=5;
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (32, "foo");
+INSERT INTO t5 VALUES (23, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (3, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+SELECT * FROM t5;
+a b
+5 foo
+6 foo
+7 foo
+8 foo
+9 foo
+32 foo
+23 foo
+33 foo
+34 foo
+3 foo
+35 foo
+OPTIMIZE TABLE t5;
+Table Op Msg_type Msg_text
+test.t5 optimize status OK
+SELECT * FROM t5;
+a b
+5 foo
+6 foo
+7 foo
+8 foo
+9 foo
+32 foo
+23 foo
+33 foo
+34 foo
+3 foo
+35 foo
+SELECT * FROM t5 WHERE a=32;
+a b
+32 foo
+SELECT * FROM t5 WHERE a=3;
+a b
+3 foo
DROP TABLE t5;
CREATE TABLE `t5` (
`a` int(11) NOT NULL auto_increment,
b char(12),
KEY (`a`)
) ENGINE=ARCHIVE DEFAULT CHARSET=latin1;
-INSERT INTO t5 VALUES (0, "foo");
-INSERT INTO t5 VALUES (0, "foo");
-INSERT INTO t5 VALUES (0, "foo");
-INSERT INTO t5 VALUES (0, "foo");
-INSERT INTO t5 VALUES (0, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
INSERT INTO t5 VALUES (32, "foo");
INSERT INTO t5 VALUES (23, "foo");
-INSERT INTO t5 VALUES (0, "foo");
-INSERT INTO t5 VALUES (0, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
INSERT INTO t5 VALUES (3, "foo");
-INSERT INTO t5 VALUES (0, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
SELECT * FROM t5;
a b
1 foo
diff --git a/mysql-test/t/archive.test b/mysql-test/t/archive.test
index 52f789f2e3f..bd8ca4e664b 100644
--- a/mysql-test/t/archive.test
+++ b/mysql-test/t/archive.test
@@ -1363,20 +1363,48 @@ b char(12),
PRIMARY KEY (`a`)
) ENGINE=ARCHIVE DEFAULT CHARSET=latin1;
-INSERT INTO t5 VALUES (0, "foo");
-INSERT INTO t5 VALUES (0, "foo");
-INSERT INTO t5 VALUES (0, "foo");
-INSERT INTO t5 VALUES (0, "foo");
-INSERT INTO t5 VALUES (0, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
INSERT INTO t5 VALUES (32, "foo");
INSERT INTO t5 VALUES (23, "foo");
-INSERT INTO t5 VALUES (0, "foo");
-INSERT INTO t5 VALUES (0, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
--error 1022
INSERT INTO t5 VALUES (3, "foo");
-INSERT INTO t5 VALUES (0, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
SELECT * FROM t5;
+SELECT * FROM t5 WHERE a=3;
+
+DROP TABLE t5;
+
+CREATE TABLE `t5` (
+`a` int(11) NOT NULL auto_increment,
+b char(12),
+KEY (`a`)
+) ENGINE=ARCHIVE DEFAULT CHARSET=latin1 AUTO_INCREMENT=5;
+
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (32, "foo");
+INSERT INTO t5 VALUES (23, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (3, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+SELECT * FROM t5;
+OPTIMIZE TABLE t5;
+SELECT * FROM t5;
+
+SELECT * FROM t5 WHERE a=32;
+SELECT * FROM t5 WHERE a=3;
+
DROP TABLE t5;
CREATE TABLE `t5` (
@@ -1385,17 +1413,17 @@ b char(12),
KEY (`a`)
) ENGINE=ARCHIVE DEFAULT CHARSET=latin1;
-INSERT INTO t5 VALUES (0, "foo");
-INSERT INTO t5 VALUES (0, "foo");
-INSERT INTO t5 VALUES (0, "foo");
-INSERT INTO t5 VALUES (0, "foo");
-INSERT INTO t5 VALUES (0, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
INSERT INTO t5 VALUES (32, "foo");
INSERT INTO t5 VALUES (23, "foo");
-INSERT INTO t5 VALUES (0, "foo");
-INSERT INTO t5 VALUES (0, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
INSERT INTO t5 VALUES (3, "foo");
-INSERT INTO t5 VALUES (0, "foo");
+INSERT INTO t5 VALUES (NULL, "foo");
SELECT * FROM t5;
#
diff --git a/sql/ha_archive.cc b/sql/ha_archive.cc
index 74e7fa68499..81b3a4e2339 100644
--- a/sql/ha_archive.cc
+++ b/sql/ha_archive.cc
@@ -581,6 +581,10 @@ int ha_archive::create(const char *name, TABLE *table_arg,
int error;
DBUG_ENTER("ha_archive::create");
+ auto_increment_value= (create_info->auto_increment_value ?
+ create_info->auto_increment_value -1 :
+ (ulonglong) 0);
+
if ((create_file= my_create(fn_format(name_buff,name,"",ARM,
MY_REPLACE_EXT|MY_UNPACK_FILENAME),0,
O_RDWR | O_TRUNC,MYF(MY_WME))) < 0)
@@ -607,7 +611,7 @@ int ha_archive::create(const char *name, TABLE *table_arg,
}
}
- write_meta_file(create_file, 0, 0, FALSE);
+ write_meta_file(create_file, 0, auto_increment_value, FALSE);
my_close(create_file,MYF(0));
/*
@@ -834,7 +838,9 @@ int ha_archive::index_read_idx(byte *buf, uint index, const byte *key,
int rc= 0;
bool found= 0;
KEY *mkey= &table->s->key_info[index];
- uint k_offset= mkey->key_part->offset;
+ current_k_offset= mkey->key_part->offset;
+ current_key= key;
+ current_key_len= key_len;
DBUG_ENTER("ha_archive::index_read_idx");
@@ -858,7 +864,7 @@ int ha_archive::index_read_idx(byte *buf, uint index, const byte *key,
while (!(get_row(&archive, buf)))
{
- if (!memcmp(key, buf+k_offset, key_len))
+ if (!memcmp(current_key, buf + current_k_offset, current_key_len))
{
found= 1;
break;
@@ -872,6 +878,25 @@ error:
DBUG_RETURN(rc ? rc : HA_ERR_END_OF_FILE);
}
+
+int ha_archive::index_next(byte * buf)
+{
+ bool found= 0;
+
+ DBUG_ENTER("ha_archive::index_next");
+
+ while (!(get_row(&archive, buf)))
+ {
+ if (!memcmp(current_key, buf+current_k_offset, current_key_len))
+ {
+ found= 1;
+ break;
+ }
+ }
+
+ DBUG_RETURN(found ? 0 : HA_ERR_END_OF_FILE);
+}
+
/*
All calls that need to scan the table start with this method. If we are told
that it is a table scan we rewind the file to the beginning, otherwise
@@ -1210,6 +1235,15 @@ THR_LOCK_DATA **ha_archive::store_lock(THD *thd,
return to;
}
+void ha_archive::update_create_info(HA_CREATE_INFO *create_info)
+{
+ ha_archive::info(HA_STATUS_AUTO | HA_STATUS_CONST);
+ if (!(create_info->used_fields & HA_CREATE_USED_AUTO))
+ {
+ create_info->auto_increment_value=auto_increment_value;
+ }
+}
+
/*
Hints for optimizer, see ha_tina for more information
diff --git a/sql/ha_archive.h b/sql/ha_archive.h
index b11bdf69483..6137e647336 100644
--- a/sql/ha_archive.h
+++ b/sql/ha_archive.h
@@ -58,6 +58,9 @@ class ha_archive: public handler
ha_rows scan_rows; /* Number of rows left in scan */
bool delayed_insert; /* If the insert is delayed */
bool bulk_insert; /* If we are performing a bulk insert */
+ const byte *current_key;
+ uint current_key_len;
+ uint current_k_offset;
public:
ha_archive(TABLE_SHARE *table_arg);
@@ -85,6 +88,7 @@ public:
uint key_len, enum ha_rkey_function find_flag);
virtual int index_read_idx(byte * buf, uint index, const byte * key,
uint key_len, enum ha_rkey_function find_flag);
+ int index_next(byte * buf);
int open(const char *name, int mode, uint test_if_locked);
int close(void);
int write_row(byte * buf);
@@ -104,6 +108,7 @@ public:
int write_data_header(azio_stream *file_to_write);
void position(const byte *record);
void info(uint);
+ void update_create_info(HA_CREATE_INFO *create_info);
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info);
int optimize(THD* thd, HA_CHECK_OPT* check_opt);
int repair(THD* thd, HA_CHECK_OPT* check_opt);