Merge lp:~stewart/drizzle/embedded-innodb-create-select-transaction-arrgh into lp:~drizzle-trunk/drizzle/development

Proposed by Stewart Smith
Status: Merged
Merged at revision: 1536
Proposed branch: lp:~stewart/drizzle/embedded-innodb-create-select-transaction-arrgh
Merge into: lp:~drizzle-trunk/drizzle/development
Prerequisite: lp:~stewart/drizzle/embedded-innodb-autoincrement
Diff against target: 77 lines (+52/-0)
4 files modified
plugin/embedded_innodb/embedded_innodb_engine.cc (+25/-0)
plugin/embedded_innodb/test-suite-dir/embedded_innodb/tests/r/basic_create_select.result (+16/-0)
plugin/embedded_innodb/test-suite-dir/embedded_innodb/tests/t/basic_create_select-master.opt (+1/-0)
plugin/embedded_innodb/test-suite-dir/embedded_innodb/tests/t/basic_create_select.test (+10/-0)
To merge this branch: bzr merge lp:~stewart/drizzle/embedded-innodb-create-select-transaction-arrgh
Reviewer Review Type Date Requested Status
Jay Pipes (community) Approve
Brian Aker Pending
Drizzle Developers Pending
Review via email: mp+23815@code.launchpad.net

Description of the change

Support CREATE SELECT properly. This means we jump through an amazingly silly hoop.

To post a comment you must log in.
Revision history for this message
Jay Pipes (jaypipes) wrote :

Huh. Nice explanation in your blog post. Ugly, but it works. :)

review: Approve
1430. By Stewart Smith

Merged embedded-innodb-autoincrement into embedded-innodb-create-select-transaction-arrgh.

1431. By Stewart Smith

Merged embedded-innodb-autoincrement into embedded-innodb-create-select-transaction-arrgh.

1432. By Stewart Smith

merge trunk

1433. By Stewart Smith

merge getInitialAutoIncrementValue() calls new names for index_init and index_end()

1434. By Stewart Smith

Merged embedded-innodb-autoincrement into embedded-innodb-create-select-transaction-arrgh.

1435. By Stewart Smith

Merged embedded-innodb-autoincrement into embedded-innodb-create-select-transaction-arrgh.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugin/embedded_innodb/embedded_innodb_engine.cc'
2--- plugin/embedded_innodb/embedded_innodb_engine.cc 2010-05-17 13:02:40 +0000
3+++ plugin/embedded_innodb/embedded_innodb_engine.cc 2010-05-17 13:02:41 +0000
4@@ -1372,6 +1372,31 @@
5 ib_cursor_attach_trx(cursor, transaction);
6
7 err= ib_cursor_first(cursor);
8+ if (current_session->lex->sql_command == SQLCOM_CREATE_TABLE
9+ && err == DB_MISSING_HISTORY)
10+ {
11+ /* See https://bugs.launchpad.net/drizzle/+bug/556978
12+ *
13+ * In CREATE SELECT, transaction is started in ::store_lock
14+ * at the start of the statement, before the table is created.
15+ * This means the table doesn't exist in our snapshot,
16+ * and we get a DB_MISSING_HISTORY error on ib_cursor_first().
17+ * The way to get around this is to here, restart the transaction
18+ * and continue.
19+ *
20+ * yuck.
21+ */
22+
23+ EmbeddedInnoDBEngine *innodb_engine= static_cast<EmbeddedInnoDBEngine*>(engine);
24+ err= ib_cursor_reset(cursor);
25+ innodb_engine->doCommit(current_session, true);
26+ innodb_engine->doStartTransaction(current_session, START_TRANS_NO_OPTIONS);
27+ transaction= *get_trx(ha_session());
28+ assert(err == DB_SUCCESS);
29+ ib_cursor_attach_trx(cursor, transaction);
30+ err= ib_cursor_first(cursor);
31+ }
32+
33 assert(err == DB_SUCCESS || err == DB_END_OF_INDEX);
34
35
36
37=== added file 'plugin/embedded_innodb/test-suite-dir/embedded_innodb/tests/r/basic_create_select.result'
38--- plugin/embedded_innodb/test-suite-dir/embedded_innodb/tests/r/basic_create_select.result 1970-01-01 00:00:00 +0000
39+++ plugin/embedded_innodb/test-suite-dir/embedded_innodb/tests/r/basic_create_select.result 2010-05-17 13:02:41 +0000
40@@ -0,0 +1,16 @@
41+create table t1 (d int primary key);
42+create table t2 (d int primary key);
43+insert into t1 values ("100000000");
44+insert into t2 values (2);
45+create table t3 (d int primary key) as select t2.d from t2 union select t1.d from t1;
46+select * from t3;
47+d
48+2
49+100000000
50+show create table t3;
51+Table Create Table
52+t3 CREATE TABLE `t3` (
53+ `d` int NOT NULL,
54+ PRIMARY KEY (`d`) USING BTREE
55+) ENGINE=DEFAULT
56+drop table t1, t2, t3;
57
58=== added file 'plugin/embedded_innodb/test-suite-dir/embedded_innodb/tests/t/basic_create_select-master.opt'
59--- plugin/embedded_innodb/test-suite-dir/embedded_innodb/tests/t/basic_create_select-master.opt 1970-01-01 00:00:00 +0000
60+++ plugin/embedded_innodb/test-suite-dir/embedded_innodb/tests/t/basic_create_select-master.opt 2010-05-17 13:02:41 +0000
61@@ -0,0 +1,1 @@
62+--plugin_add=embedded_innodb --plugin_remove=innobase
63
64=== added file 'plugin/embedded_innodb/test-suite-dir/embedded_innodb/tests/t/basic_create_select.test'
65--- plugin/embedded_innodb/test-suite-dir/embedded_innodb/tests/t/basic_create_select.test 1970-01-01 00:00:00 +0000
66+++ plugin/embedded_innodb/test-suite-dir/embedded_innodb/tests/t/basic_create_select.test 2010-05-17 13:02:41 +0000
67@@ -0,0 +1,10 @@
68+create table t1 (d int primary key);
69+create table t2 (d int primary key);
70+insert into t1 values ("100000000");
71+insert into t2 values (2);
72+create table t3 (d int primary key) as select t2.d from t2 union select t1.d from t1;
73+select * from t3;
74+--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
75+show create table t3;
76+drop table t1, t2, t3;
77+