=== modified file 'plugin/embedded_innodb/embedded_innodb_engine.cc'
--- plugin/embedded_innodb/embedded_innodb_engine.cc	2010-05-17 13:02:40 +0000
+++ plugin/embedded_innodb/embedded_innodb_engine.cc	2010-05-17 13:02:41 +0000
@@ -1372,6 +1372,31 @@
   ib_cursor_attach_trx(cursor, transaction);
 
   err= ib_cursor_first(cursor);
+  if (current_session->lex->sql_command == SQLCOM_CREATE_TABLE
+      && err == DB_MISSING_HISTORY)
+  {
+    /* See https://bugs.launchpad.net/drizzle/+bug/556978
+     *
+     * In CREATE SELECT, transaction is started in ::store_lock
+     * at the start of the statement, before the table is created.
+     * This means the table doesn't exist in our snapshot,
+     * and we get a DB_MISSING_HISTORY error on ib_cursor_first().
+     * The way to get around this is to here, restart the transaction
+     * and continue.
+     *
+     * yuck.
+     */
+
+    EmbeddedInnoDBEngine *innodb_engine= static_cast<EmbeddedInnoDBEngine*>(engine);
+    err= ib_cursor_reset(cursor);
+    innodb_engine->doCommit(current_session, true);
+    innodb_engine->doStartTransaction(current_session, START_TRANS_NO_OPTIONS);
+    transaction= *get_trx(ha_session());
+    assert(err == DB_SUCCESS);
+    ib_cursor_attach_trx(cursor, transaction);
+    err= ib_cursor_first(cursor);
+  }
+
   assert(err == DB_SUCCESS || err == DB_END_OF_INDEX);
 
 

=== added file 'plugin/embedded_innodb/test-suite-dir/embedded_innodb/tests/r/basic_create_select.result'
--- plugin/embedded_innodb/test-suite-dir/embedded_innodb/tests/r/basic_create_select.result	1970-01-01 00:00:00 +0000
+++ plugin/embedded_innodb/test-suite-dir/embedded_innodb/tests/r/basic_create_select.result	2010-05-17 13:02:41 +0000
@@ -0,0 +1,16 @@
+create table t1 (d int primary key);
+create table t2 (d int primary key);
+insert into t1 values ("100000000");
+insert into t2 values (2);
+create table t3 (d int primary key) as select t2.d from t2 union select t1.d from t1;
+select * from t3;
+d
+2
+100000000
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `d` int NOT NULL,
+  PRIMARY KEY (`d`) USING BTREE
+) ENGINE=DEFAULT
+drop table t1, t2, t3;

=== added file 'plugin/embedded_innodb/test-suite-dir/embedded_innodb/tests/t/basic_create_select-master.opt'
--- plugin/embedded_innodb/test-suite-dir/embedded_innodb/tests/t/basic_create_select-master.opt	1970-01-01 00:00:00 +0000
+++ plugin/embedded_innodb/test-suite-dir/embedded_innodb/tests/t/basic_create_select-master.opt	2010-05-17 13:02:41 +0000
@@ -0,0 +1,1 @@
+--plugin_add=embedded_innodb --plugin_remove=innobase

=== added file 'plugin/embedded_innodb/test-suite-dir/embedded_innodb/tests/t/basic_create_select.test'
--- plugin/embedded_innodb/test-suite-dir/embedded_innodb/tests/t/basic_create_select.test	1970-01-01 00:00:00 +0000
+++ plugin/embedded_innodb/test-suite-dir/embedded_innodb/tests/t/basic_create_select.test	2010-05-17 13:02:41 +0000
@@ -0,0 +1,10 @@
+create table t1 (d int primary key);
+create table t2 (d int primary key);
+insert into t1 values ("100000000");
+insert into t2 values (2);
+create table t3 (d int primary key) as select t2.d from t2 union select t1.d from t1;
+select * from t3;
+--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
+show create table t3;
+drop table t1, t2, t3;
+

