List:Commits« Previous MessageNext Message »
From:Magnus Blåudd Date:July 9 2009 3:11pm
Subject:bzr commit into mysql-5.1-telco-7.1 branch (magnus.blaudd:2939)
View as plain text  
#At file:///home/msvensson/mysql/tmp/qJMOu3zPfR/7.1-ndbinfo/ based on revid:magnus.blaudd@strippedm-20090708092325-ocuj82s4dzdcs2ev

 2939 Magnus Blåudd	2009-07-09 [merge]
      Merge

    modified:
      client/mysqlcheck.c
      client/mysqldump.c
      mysql-test/r/1st.result
      mysql-test/r/drop.result
      mysql-test/r/information_schema.result
      mysql-test/r/ps_1general.result
      mysql-test/r/schema.result
      mysql-test/r/show_check.result
      mysql-test/suite/binlog/r/binlog_database.result
      mysql-test/suite/ndb/r/ndb_restore_options.result
      mysql-test/suite/ndb/r/ndbinfo.result
      mysql-test/suite/ndb/t/ndbinfo.test
      mysql-test/suite/rpl/r/rpl_loaddata_m.result
      mysql-test/suite/rpl/r/rpl_row_basic_11bugs.result
      scripts/mysql_system_tables.sql
      sql/ha_ndbinfo.cc
      storage/ndb/include/util/HashMap.hpp
      storage/ndb/src/kernel/blocks/dbinfo/Dbinfo.cpp
      storage/ndb/src/kernel/vm/Ndbinfo.cpp
      storage/ndb/src/kernel/vm/Ndbinfo.hpp
      storage/ndb/src/ndbapi/NdbInfo.cpp
      storage/ndb/src/ndbapi/NdbInfo.hpp
      storage/ndb/src/ndbapi/NdbInfoScanOperation.cpp
      storage/ndb/src/ndbapi/NdbInfoScanOperation.hpp
      storage/ndb/test/ndbapi/testNdbinfo.cpp
=== modified file 'client/mysqlcheck.c'
--- a/client/mysqlcheck.c	2009-05-27 12:11:46 +0000
+++ b/client/mysqlcheck.c	2009-07-09 15:04:27 +0000
@@ -649,6 +649,9 @@ static int use_db(char *database)
   if (mysql_get_server_version(sock) >= 50003 &&
       !my_strcasecmp(&my_charset_latin1, database, "information_schema"))
     return 1;
+  if (mysql_get_server_version(sock) >= 50135 &&
+      !my_strcasecmp(&my_charset_latin1, database, "ndb$info"))
+    return 1;
   if (mysql_select_db(sock, database))
   {
     DBerror(sock, "when selecting the database");

=== modified file 'client/mysqldump.c'
--- a/client/mysqldump.c	2009-05-27 12:11:46 +0000
+++ b/client/mysqldump.c	2009-07-09 15:04:27 +0000
@@ -3946,6 +3946,10 @@ static int init_dumping(char *database, 
       !my_strcasecmp(&my_charset_latin1, database, "information_schema"))
     return 1;
 
+  if (mysql_get_server_version(mysql) >= 50135 &&
+      !my_strcasecmp(&my_charset_latin1, database, "ndb$info"))
+    return 1;
+
   if (mysql_select_db(mysql, database))
   {
     DB_error(mysql, "when selecting the database");

=== modified file 'mysql-test/r/1st.result'
--- a/mysql-test/r/1st.result	2008-04-02 08:06:36 +0000
+++ b/mysql-test/r/1st.result	2009-07-09 15:04:27 +0000
@@ -3,6 +3,7 @@ Database
 information_schema
 mtr
 mysql
+ndb$info
 test
 show tables in mysql;
 Tables_in_mysql

=== modified file 'mysql-test/r/drop.result'
--- a/mysql-test/r/drop.result	2008-04-03 09:50:43 +0000
+++ b/mysql-test/r/drop.result	2009-07-09 15:04:27 +0000
@@ -50,6 +50,7 @@ information_schema
 mtr
 mysql
 mysqltest
+ndb$info
 test
 flush tables with read lock;
 drop database mysqltest;
@@ -61,6 +62,7 @@ Database
 information_schema
 mtr
 mysql
+ndb$info
 test
 drop database mysqltest;
 ERROR HY000: Can't drop database 'mysqltest'; database doesn't exist

=== modified file 'mysql-test/r/information_schema.result'
--- a/mysql-test/r/information_schema.result	2009-05-08 14:43:21 +0000
+++ b/mysql-test/r/information_schema.result	2009-07-09 15:04:27 +0000
@@ -11,12 +11,14 @@ select * from information_schema.SCHEMAT
 CATALOG_NAME	SCHEMA_NAME	DEFAULT_CHARACTER_SET_NAME	DEFAULT_COLLATION_NAME	SQL_PATH
 NULL	mtr	latin1	latin1_swedish_ci	NULL
 NULL	mysql	latin1	latin1_swedish_ci	NULL
+NULL	ndb$info	latin1	latin1_swedish_ci	NULL
 NULL	test	latin1	latin1_swedish_ci	NULL
 select schema_name from information_schema.schemata;
 schema_name
 information_schema
 mtr
 mysql
+ndb$info
 test
 show databases like 't%';
 Database (t%)
@@ -26,6 +28,7 @@ Database
 information_schema
 mtr
 mysql
+ndb$info
 test
 show databases where `database` = 't%';
 Database
@@ -360,6 +363,7 @@ c
 information_schema
 mtr
 mysql
+ndb$info
 test
 explain select * from v0;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra

=== modified file 'mysql-test/r/ps_1general.result'
--- a/mysql-test/r/ps_1general.result	2009-04-01 08:58:55 +0000
+++ b/mysql-test/r/ps_1general.result	2009-07-09 15:04:27 +0000
@@ -262,6 +262,7 @@ Database
 information_schema
 mtr
 mysql
+ndb$info
 test
 prepare stmt4 from ' show tables from test like ''t2%'' ';
 execute stmt4;

=== modified file 'mysql-test/r/schema.result'
--- a/mysql-test/r/schema.result	2008-04-02 08:06:36 +0000
+++ b/mysql-test/r/schema.result	2009-07-09 15:04:27 +0000
@@ -9,5 +9,6 @@ information_schema
 foo
 mtr
 mysql
+ndb$info
 test
 drop schema foo;

=== modified file 'mysql-test/r/show_check.result'
--- a/mysql-test/r/show_check.result	2009-03-06 14:56:17 +0000
+++ b/mysql-test/r/show_check.result	2009-07-09 15:04:27 +0000
@@ -142,6 +142,7 @@ Database
 information_schema
 mtr
 mysql
+ndb$info
 test
 show databases like "test%";
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr

=== modified file 'mysql-test/suite/binlog/r/binlog_database.result'
--- a/mysql-test/suite/binlog/r/binlog_database.result	2009-01-23 12:22:05 +0000
+++ b/mysql-test/suite/binlog/r/binlog_database.result	2009-07-09 15:04:27 +0000
@@ -116,4 +116,5 @@ Database
 information_schema
 mtr
 mysql
+ndb$info
 test

=== modified file 'mysql-test/suite/ndb/r/ndb_restore_options.result'
--- a/mysql-test/suite/ndb/r/ndb_restore_options.result	2009-05-08 17:58:13 +0000
+++ b/mysql-test/suite/ndb/r/ndb_restore_options.result	2009-07-09 15:04:27 +0000
@@ -406,6 +406,7 @@ db1
 db2
 mtr
 mysql
+ndb$info
 test
 use db1;
 show tables;
@@ -424,6 +425,7 @@ db1
 db2
 mtr
 mysql
+ndb$info
 test
 use db1;
 show tables;

=== modified file 'mysql-test/suite/ndb/r/ndbinfo.result'
--- a/mysql-test/suite/ndb/r/ndbinfo.result	2009-07-08 08:45:00 +0000
+++ b/mysql-test/suite/ndb/r/ndbinfo.result	2009-07-09 15:04:27 +0000
@@ -5,7 +5,6 @@ select * from information_schema.plugins
 PLUGIN_NAME	PLUGIN_VERSION	PLUGIN_STATUS	PLUGIN_TYPE	PLUGIN_TYPE_VERSION	PLUGIN_LIBRARY	PLUGIN_LIBRARY_VERSION	PLUGIN_AUTHOR	PLUGIN_DESCRIPTION	PLUGIN_LICENSE
 ndbinfo	0.1	ACTIVE	STORAGE ENGINE	50135.0	NULL	NULL	Sun Microsystems Inc.	Ndb system information storage engine	GPL
 
-CREATE DATABASE ndb$info;
 use ndb$info;
 
 ## Creation of temporary tables should not be supported
@@ -16,34 +15,28 @@ CREATE TEMPORARY TABLE `TABLES` (
 ) ENGINE=NDBINFO;
 ERROR HY000: Table storage engine 'ndbinfo' does not support the create option 'TEMPORARY'
 
-CREATE TABLE `TABLES` (
-  `TABLE_ID` INT UNSIGNED,
-  `TABLE_NAME` VARCHAR(512),
-  `CREATE_SQL` VARCHAR(512)
-) ENGINE=NDBINFO;
-
-SHOW CREATE TABLE TABLES;
+SHOW CREATE TABLE NDB$TABLES;
 Table	Create Table
-TABLES	CREATE TABLE `TABLES` (
+NDB$TABLES	CREATE TABLE `NDB$TABLES` (
   `TABLE_ID` int(10) unsigned DEFAULT NULL,
   `TABLE_NAME` varchar(512) DEFAULT NULL,
   `CREATE_SQL` varchar(512) DEFAULT NULL
 ) ENGINE=NDBINFO DEFAULT CHARSET=latin1
 
-select * from TABLES;
+select * from NDB$TABLES;
 TABLE_ID	TABLE_NAME	CREATE_SQL
-0	TABLES	CREATE TABLE `TABLES` (
+0	TABLES	CREATE TABLE `ndb$info`.`NDB$TABLES` (
 	`TABLE_ID` INT UNSIGNED,
 	`TABLE_NAME` VARCHAR(512),
 	`CREATE_SQL` VARCHAR(512)
 ) ENGINE=NDBINFO;
-1	COLUMNS	CREATE TABLE `COLUMNS` (
+1	COLUMNS	CREATE TABLE `ndb$info`.`NDB$COLUMNS` (
 	`TABLE_ID` INT UNSIGNED,
 	`COLUMN_ID` INT UNSIGNED,
 	`COLUMN_NAME` VARCHAR(512),
 	`COLUMN_TYPE` VARCHAR(512)
 ) ENGINE=NDBINFO;
-2	MEMUSAGE	CREATE TABLE `MEMUSAGE` (
+2	MEMUSAGE	CREATE TABLE `ndb$info`.`NDB$MEMUSAGE` (
 	`NODE_ID` INT UNSIGNED,
 	`BLOCK_NUMBER` INT UNSIGNED,
 	`BLOCK_INSTANCE` INT UNSIGNED,
@@ -52,14 +45,14 @@ TABLE_ID	TABLE_NAME	CREATE_SQL
 	`PAGES_USED` INT UNSIGNED,
 	`PAGES_TOTAL` INT UNSIGNED
 ) ENGINE=NDBINFO;
-3	LOGDESTINATION	CREATE TABLE `LOGDESTINATION` (
+3	LOGDESTINATION	CREATE TABLE `ndb$info`.`NDB$LOGDESTINATION` (
 	`NODE_ID` INT UNSIGNED,
 	`TYPE` VARCHAR(512),
 	`PARAMS` VARCHAR(512),
 	`CURRENT_SIZE` INT UNSIGNED,
 	`MAX_SIZE` INT UNSIGNED
 ) ENGINE=NDBINFO;
-4	BACKUP_RECORDS	CREATE TABLE `BACKUP_RECORDS` (
+4	BACKUP_RECORDS	CREATE TABLE `ndb$info`.`NDB$BACKUP_RECORDS` (
 	`NODE_ID` INT UNSIGNED,
 	`BACKUP_RECORD` INT UNSIGNED,
 	`BACKUP_ID` INT UNSIGNED,
@@ -72,7 +65,7 @@ TABLE_ID	TABLE_NAME	CREATE_SQL
 	`LOG_RECORDS` INT UNSIGNED,
 	`ERROR_CODE` INT UNSIGNED
 ) ENGINE=NDBINFO;
-5	BACKUP_PARAMETERS	CREATE TABLE `BACKUP_PARAMETERS` (
+5	BACKUP_PARAMETERS	CREATE TABLE `ndb$info`.`NDB$BACKUP_PARAMETERS` (
 	`NODE_ID` INT UNSIGNED,
 	`CURRENT_DISK_WRITE_SPEED` INT UNSIGNED,
 	`BYTES_WRITTEN_THIS_PERIOD` INT UNSIGNED,
@@ -85,9 +78,8 @@ TABLE_ID	TABLE_NAME	CREATE_SQL
 	`TRIGGER_POOL_SIZE` INT UNSIGNED,
 	`FRAGMENT_POOL_SIZE` INT UNSIGNED,
 	`PAGE_POOL_SIZE` INT UNSIGNED,
-	`COMPRESSED_BACKUP` INT UNSIGNED,
-	`COMPRESSE
-6	POOLS	CREATE TABLE `POOLS` (
+	`COMPRESSED_BACKUP` INT UNSIGNE
+6	POOLS	CREATE TABLE `ndb$info`.`NDB$POOLS` (
 	`NODE_ID` INT UNSIGNED,
 	`BLOCK_NUMBER` INT UNSIGNED,
 	`BLOCK_INSTANCE` INT UNSIGNED,
@@ -95,18 +87,18 @@ TABLE_ID	TABLE_NAME	CREATE_SQL
 	`FREE` INT UNSIGNED,
 	`SIZE` INT UNSIGNED
 ) ENGINE=NDBINFO;
-7	TEST	CREATE TABLE `TEST` (
+7	TEST	CREATE TABLE `ndb$info`.`NDB$TEST` (
 	`NODE_ID` INT UNSIGNED,
 	`BLOCK_NUMBER` INT UNSIGNED,
 	`BLOCK_INSTANCE` INT UNSIGNED,
 	`COUNTER` INT UNSIGNED
 ) ENGINE=NDBINFO;
-select count(*) from TABLES;
+select count(*) from NDB$TABLES;
 count(*)
 8
-select * from TABLES where TABLE_ID = 2;
+select * from NDB$TABLES where TABLE_ID = 2;
 TABLE_ID	TABLE_NAME	CREATE_SQL
-2	MEMUSAGE	CREATE TABLE `MEMUSAGE` (
+2	MEMUSAGE	CREATE TABLE `ndb$info`.`NDB$MEMUSAGE` (
 	`NODE_ID` INT UNSIGNED,
 	`BLOCK_NUMBER` INT UNSIGNED,
 	`BLOCK_INSTANCE` INT UNSIGNED,
@@ -115,9 +107,9 @@ TABLE_ID	TABLE_NAME	CREATE_SQL
 	`PAGES_USED` INT UNSIGNED,
 	`PAGES_TOTAL` INT UNSIGNED
 ) ENGINE=NDBINFO;
-select * from TABLES where TABLE_ID > 5;
+select * from NDB$TABLES where TABLE_ID > 5;
 TABLE_ID	TABLE_NAME	CREATE_SQL
-6	POOLS	CREATE TABLE `POOLS` (
+6	POOLS	CREATE TABLE `ndb$info`.`NDB$POOLS` (
 	`NODE_ID` INT UNSIGNED,
 	`BLOCK_NUMBER` INT UNSIGNED,
 	`BLOCK_INSTANCE` INT UNSIGNED,
@@ -125,36 +117,36 @@ TABLE_ID	TABLE_NAME	CREATE_SQL
 	`FREE` INT UNSIGNED,
 	`SIZE` INT UNSIGNED
 ) ENGINE=NDBINFO;
-7	TEST	CREATE TABLE `TEST` (
+7	TEST	CREATE TABLE `ndb$info`.`NDB$TEST` (
 	`NODE_ID` INT UNSIGNED,
 	`BLOCK_NUMBER` INT UNSIGNED,
 	`BLOCK_INSTANCE` INT UNSIGNED,
 	`COUNTER` INT UNSIGNED
 ) ENGINE=NDBINFO;
-select * from TABLES where TABLE_NAME = 'LOGDESTINATION';
+select * from NDB$TABLES where TABLE_NAME = 'LOGDESTINATION';
 TABLE_ID	TABLE_NAME	CREATE_SQL
-3	LOGDESTINATION	CREATE TABLE `LOGDESTINATION` (
+3	LOGDESTINATION	CREATE TABLE `ndb$info`.`NDB$LOGDESTINATION` (
 	`NODE_ID` INT UNSIGNED,
 	`TYPE` VARCHAR(512),
 	`PARAMS` VARCHAR(512),
 	`CURRENT_SIZE` INT UNSIGNED,
 	`MAX_SIZE` INT UNSIGNED
 ) ENGINE=NDBINFO;
-select count(*) from TABLES t1, TABLES t2 WHERE t1.TABLE_ID = t1.TABLE_ID;
+select count(*) from NDB$TABLES t1, NDB$TABLES t2 WHERE t1.TABLE_ID = t1.TABLE_ID;
 count(*)
 64
 
-select TABLE_ID, TABLE_NAME, CREATE_SQL from TABLES
+select TABLE_ID, TABLE_NAME, CREATE_SQL from NDB$TABLES
   where TABLE_ID > 2 and TABLE_ID <= 5 order by TABLE_ID;
 TABLE_ID	TABLE_NAME	CREATE_SQL
-3	LOGDESTINATION	CREATE TABLE `LOGDESTINATION` (
+3	LOGDESTINATION	CREATE TABLE `ndb$info`.`NDB$LOGDESTINATION` (
 	`NODE_ID` INT UNSIGNED,
 	`TYPE` VARCHAR(512),
 	`PARAMS` VARCHAR(512),
 	`CURRENT_SIZE` INT UNSIGNED,
 	`MAX_SIZE` INT UNSIGNED
 ) ENGINE=NDBINFO;
-4	BACKUP_RECORDS	CREATE TABLE `BACKUP_RECORDS` (
+4	BACKUP_RECORDS	CREATE TABLE `ndb$info`.`NDB$BACKUP_RECORDS` (
 	`NODE_ID` INT UNSIGNED,
 	`BACKUP_RECORD` INT UNSIGNED,
 	`BACKUP_ID` INT UNSIGNED,
@@ -167,7 +159,7 @@ TABLE_ID	TABLE_NAME	CREATE_SQL
 	`LOG_RECORDS` INT UNSIGNED,
 	`ERROR_CODE` INT UNSIGNED
 ) ENGINE=NDBINFO;
-5	BACKUP_PARAMETERS	CREATE TABLE `BACKUP_PARAMETERS` (
+5	BACKUP_PARAMETERS	CREATE TABLE `ndb$info`.`NDB$BACKUP_PARAMETERS` (
 	`NODE_ID` INT UNSIGNED,
 	`CURRENT_DISK_WRITE_SPEED` INT UNSIGNED,
 	`BYTES_WRITTEN_THIS_PERIOD` INT UNSIGNED,
@@ -180,12 +172,11 @@ TABLE_ID	TABLE_NAME	CREATE_SQL
 	`TRIGGER_POOL_SIZE` INT UNSIGNED,
 	`FRAGMENT_POOL_SIZE` INT UNSIGNED,
 	`PAGE_POOL_SIZE` INT UNSIGNED,
-	`COMPRESSED_BACKUP` INT UNSIGNED,
-	`COMPRESSE
-select TABLE_ID from TABLES  WHERE TABLE_ID = 2 order by TABLE_NAME;
+	`COMPRESSED_BACKUP` INT UNSIGNE
+select TABLE_ID from NDB$TABLES  WHERE TABLE_ID = 2 order by TABLE_NAME;
 TABLE_ID
 2
-select TABLE_ID, TABLE_NAME from TABLES order by TABLE_NAME;
+select TABLE_ID, TABLE_NAME from NDB$TABLES order by TABLE_NAME;
 TABLE_ID	TABLE_NAME
 5	BACKUP_PARAMETERS
 4	BACKUP_RECORDS
@@ -196,43 +187,36 @@ TABLE_ID	TABLE_NAME
 0	TABLES
 7	TEST
 
-CREATE TABLE `COLUMNS` (
-  `TABLE_ID` INT UNSIGNED,
-  `COLUMN_ID` INT UNSIGNED,
-  `COLUMN_NAME` VARCHAR(512),
-  `COLUMN_TYPE` VARCHAR(512)
-) ENGINE=NDBINFO;
-
-select TABLE_ID, COLUMN_ID, COLUMN_NAME from COLUMNS LIMIT 7;
+select TABLE_ID, COLUMN_ID, COLUMN_NAME from NDB$COLUMNS LIMIT 7;
 TABLE_ID	COLUMN_ID	COLUMN_NAME
 0	0	TABLE_ID
 0	1	TABLE_NAME
-0	2	CREATE_SQL
 1	0	TABLE_ID
 1	1	COLUMN_ID
 1	2	COLUMN_NAME
 1	3	COLUMN_TYPE
+2	0	NODE_ID
 
-update TABLES set TABLE_ID=2 where TABLE_ID=3;
-ERROR HY000: Table 'TABLES' is read only
+update NDB$TABLES set TABLE_ID=2 where TABLE_ID=3;
+ERROR HY000: Table 'NDB$TABLES' is read only
 
-update TABLES set TABLE_ID=9 where 1=0;
-ERROR HY000: Table 'TABLES' is read only
+update NDB$TABLES set TABLE_ID=9 where 1=0;
+ERROR HY000: Table 'NDB$TABLES' is read only
 
-update TABLES set TABLE_ID=9 where TABLE_ID > 1;
-ERROR HY000: Table 'TABLES' is read only
+update NDB$TABLES set TABLE_ID=9 where TABLE_ID > 1;
+ERROR HY000: Table 'NDB$TABLES' is read only
 
-delete from TABLES where TABLE_ID=3;
-ERROR HY000: Table 'TABLES' is read only
+delete from NDB$TABLES where TABLE_ID=3;
+ERROR HY000: Table 'NDB$TABLES' is read only
 
-delete from TABLES where 1=0;
-ERROR HY000: Table 'TABLES' is read only
+delete from NDB$TABLES where 1=0;
+ERROR HY000: Table 'NDB$TABLES' is read only
 
-delete from TABLES where TABLE_ID > 1;
-ERROR HY000: Table 'TABLES' is read only
+delete from NDB$TABLES where TABLE_ID > 1;
+ERROR HY000: Table 'NDB$TABLES' is read only
 
-FLUSH  TABLES;
-SELECT TABLE_ID from TABLES;
+FLUSH TABLES;
+SELECT TABLE_ID from NDB$TABLES;
 TABLE_ID
 0
 1
@@ -251,6 +235,12 @@ Variable_name	Value
 ndbinfo_max_bytes	0
 ndbinfo_max_rows	10
 
+CREATE TABLE `ndb$info`.`NDB$TEST`(
+  `NODE_ID` INT UNSIGNED,
+  `BLOCK_NUMBER` INT UNSIGNED,
+  `BLOCK_INSTANCE` INT UNSIGNED,
+  `COUNTER` INT UNSIGNED
+) ENGINE=NDBINFO;
+
 ## Cleanup
-drop table TABLES;
-DROP DATABASE ndb$info;
+DROP TABLE NDB$TEST;

=== modified file 'mysql-test/suite/ndb/t/ndbinfo.test'
--- a/mysql-test/suite/ndb/t/ndbinfo.test	2009-07-08 08:45:00 +0000
+++ b/mysql-test/suite/ndb/t/ndbinfo.test	2009-07-09 15:04:27 +0000
@@ -3,7 +3,6 @@
 
 select * from information_schema.plugins where PLUGIN_NAME = 'ndbinfo';
 
-CREATE DATABASE ndb$info;
 use ndb$info;
 
 ## Creation of temporary tables should not be supported
@@ -14,68 +13,64 @@ CREATE TEMPORARY TABLE `TABLES` (
   `CREATE_SQL` VARCHAR(512)
 ) ENGINE=NDBINFO;
 
-CREATE TABLE `TABLES` (
-  `TABLE_ID` INT UNSIGNED,
-  `TABLE_NAME` VARCHAR(512),
-  `CREATE_SQL` VARCHAR(512)
-) ENGINE=NDBINFO;
-
-SHOW CREATE TABLE TABLES;
+# replace for lower_case_table_names
+--replace_result tables NDB$TABLES
+SHOW CREATE TABLE NDB$TABLES;
 
-select * from TABLES;
-select count(*) from TABLES;
-select * from TABLES where TABLE_ID = 2;
-select * from TABLES where TABLE_ID > 5;
-select * from TABLES where TABLE_NAME = 'LOGDESTINATION';
-select count(*) from TABLES t1, TABLES t2 WHERE t1.TABLE_ID = t1.TABLE_ID;
+select * from NDB$TABLES;
+select count(*) from NDB$TABLES;
+select * from NDB$TABLES where TABLE_ID = 2;
+select * from NDB$TABLES where TABLE_ID > 5;
+select * from NDB$TABLES where TABLE_NAME = 'LOGDESTINATION';
+select count(*) from NDB$TABLES t1, NDB$TABLES t2 WHERE t1.TABLE_ID = t1.TABLE_ID;
 
-select TABLE_ID, TABLE_NAME, CREATE_SQL from TABLES
+select TABLE_ID, TABLE_NAME, CREATE_SQL from NDB$TABLES
   where TABLE_ID > 2 and TABLE_ID <= 5 order by TABLE_ID;
-select TABLE_ID from TABLES  WHERE TABLE_ID = 2 order by TABLE_NAME;
-select TABLE_ID, TABLE_NAME from TABLES order by TABLE_NAME;
+select TABLE_ID from NDB$TABLES  WHERE TABLE_ID = 2 order by TABLE_NAME;
+select TABLE_ID, TABLE_NAME from NDB$TABLES order by TABLE_NAME;
 
-CREATE TABLE `COLUMNS` (
-  `TABLE_ID` INT UNSIGNED,
-  `COLUMN_ID` INT UNSIGNED,
-  `COLUMN_NAME` VARCHAR(512),
-  `COLUMN_TYPE` VARCHAR(512)
-) ENGINE=NDBINFO;
-
-select TABLE_ID, COLUMN_ID, COLUMN_NAME from COLUMNS LIMIT 7;
+select TABLE_ID, COLUMN_ID, COLUMN_NAME from NDB$COLUMNS LIMIT 7;
 
 # replace for lower_case_table_names
---replace_result tables TABLES
+--replace_result tables NDB$TABLES
 --error ER_OPEN_AS_READONLY
-update TABLES set TABLE_ID=2 where TABLE_ID=3;
+update NDB$TABLES set TABLE_ID=2 where TABLE_ID=3;
 
---replace_result tables TABLES
+--replace_result tables NDB$TABLES
 --error ER_OPEN_AS_READONLY
-update TABLES set TABLE_ID=9 where 1=0;
+update NDB$TABLES set TABLE_ID=9 where 1=0;
 
---replace_result tables TABLES
+--replace_result tables NDB$TABLES
 --error ER_OPEN_AS_READONLY
-update TABLES set TABLE_ID=9 where TABLE_ID > 1;
+update NDB$TABLES set TABLE_ID=9 where TABLE_ID > 1;
 
---replace_result tables TABLES
+--replace_result tables NDB$TABLES
 --error ER_OPEN_AS_READONLY
-delete from TABLES where TABLE_ID=3;
+delete from NDB$TABLES where TABLE_ID=3;
 
---replace_result tables TABLES
+--replace_result tables NDB$TABLES
 --error ER_OPEN_AS_READONLY
-delete from TABLES where 1=0;
+delete from NDB$TABLES where 1=0;
 
---replace_result tables TABLES
+--replace_result tables NDB$TABLES
 --error ER_OPEN_AS_READONLY
-delete from TABLES where TABLE_ID > 1;
+delete from NDB$TABLES where TABLE_ID > 1;
 
-FLUSH  TABLES;
-SELECT TABLE_ID from TABLES;
+FLUSH TABLES;
+SELECT TABLE_ID from NDB$TABLES;
 
 
 ## Variables and status
 SHOW GLOBAL STATUS LIKE 'ndbinfo\_%';
 SHOW GLOBAL VARIABLES LIKE 'ndbinfo\_%';
 
+# Create the test table(this also shows that it's hidden by default)
+CREATE TABLE `ndb$info`.`NDB$TEST`(
+  `NODE_ID` INT UNSIGNED,
+  `BLOCK_NUMBER` INT UNSIGNED,
+  `BLOCK_INSTANCE` INT UNSIGNED,
+  `COUNTER` INT UNSIGNED
+) ENGINE=NDBINFO;
+
 ## Cleanup
-drop table TABLES;
-DROP DATABASE ndb$info;
+DROP TABLE NDB$TEST;
\ No newline at end of file

=== modified file 'mysql-test/suite/rpl/r/rpl_loaddata_m.result'
--- a/mysql-test/suite/rpl/r/rpl_loaddata_m.result	2008-04-02 08:06:36 +0000
+++ b/mysql-test/suite/rpl/r/rpl_loaddata_m.result	2009-07-09 15:04:27 +0000
@@ -24,6 +24,7 @@ information_schema
 mtr
 mysql
 mysqltest
+ndb$info
 test
 USE test;
 SHOW TABLES;

=== modified file 'mysql-test/suite/rpl/r/rpl_row_basic_11bugs.result'
--- a/mysql-test/suite/rpl/r/rpl_row_basic_11bugs.result	2009-02-03 13:35:56 +0000
+++ b/mysql-test/suite/rpl/r/rpl_row_basic_11bugs.result	2009-07-09 15:04:27 +0000
@@ -11,6 +11,7 @@ Database
 information_schema
 mtr
 mysql
+ndb$info
 test
 test_ignore
 USE test;
@@ -38,6 +39,7 @@ Database
 information_schema
 mtr
 mysql
+ndb$info
 test
 USE test;
 SHOW TABLES;

=== modified file 'scripts/mysql_system_tables.sql'
--- a/scripts/mysql_system_tables.sql	2009-05-08 09:57:18 +0000
+++ b/scripts/mysql_system_tables.sql	2009-07-09 15:04:27 +0000
@@ -85,3 +85,88 @@ CREATE TABLE IF NOT EXISTS event ( db ch
 
 CREATE TABLE IF NOT EXISTS ndb_binlog_index (Position BIGINT UNSIGNED NOT NULL, File VARCHAR(255) NOT NULL, epoch BIGINT UNSIGNED NOT NULL, inserts INT UNSIGNED NOT NULL, updates INT UNSIGNED NOT NULL, deletes INT UNSIGNED NOT NULL, schemaops INT UNSIGNED NOT NULL, orig_server_id INT UNSIGNED NOT NULL, orig_epoch BIGINT UNSIGNED NOT NULL, gci INT UNSIGNED NOT NULL, PRIMARY KEY(epoch, orig_server_id, orig_epoch)) ENGINE=MYISAM;
 
+--
+-- ndb$info tables
+--
+-- Always create ndb$info database
+CREATE DATABASE IF NOT EXISTS `ndb$info`;
+
+-- Only create tables if NDBINFO is enabled
+SELECT @have_ndbinfo:= COUNT(*) FROM information_schema.engines WHERE engine='NDBINFO' AND support IN ('YES', 'DEFAULT');
+
+-- ndb$info.TABLES
+SET @str=IF(@have_ndbinfo,'DROP TABLE IF EXISTS `ndb$info`.`NDB$TABLES`','SET @dummy = 0');
+PREPARE stmt FROM @str;
+EXECUTE stmt;
+DROP PREPARE stmt;
+
+SET @str=IF(@have_ndbinfo,'CREATE TABLE `ndb$info`.`NDB$TABLES` (`TABLE_ID` INT UNSIGNED,`TABLE_NAME` VARCHAR(512),`CREATE_SQL` VARCHAR(512)) ENGINE=NDBINFO;','SET @dummy = 0');
+PREPARE stmt FROM @str;
+EXECUTE stmt;
+DROP PREPARE stmt;
+
+-- ndb$info.COLUMNS
+SET @str=IF(@have_ndbinfo,'DROP TABLE IF EXISTS `ndb$info`.`NDB$COLUMNS`','SET @dummy = 0');
+PREPARE stmt FROM @str;
+EXECUTE stmt;
+DROP PREPARE stmt;
+
+SET @str=IF(@have_ndbinfo,'CREATE TABLE `ndb$info`.`NDB$COLUMNS` (`TABLE_ID` INT UNSIGNED,`COLUMN_ID` INT UNSIGNED,`COLUMN_NAME` VARCHAR(512),`COLUMN_TYPE` VARCHAR(512)) ENGINE=NDBINFO;','SET @dummy = 0');
+PREPARE stmt FROM @str;
+EXECUTE stmt;
+DROP PREPARE stmt;
+
+-- ndb$info.MEMUSAGE
+SET @str=IF(@have_ndbinfo,'DROP TABLE IF EXISTS `ndb$info`.`NDB$MEMUSAGE`','SET @dummy = 0');
+PREPARE stmt FROM @str;
+EXECUTE stmt;
+DROP PREPARE stmt;
+
+SET @str=IF(@have_ndbinfo,'CREATE TABLE `ndb$info`.`NDB$MEMUSAGE` (`NODE_ID` INT UNSIGNED,`BLOCK_NUMBER` INT UNSIGNED,`BLOCK_INSTANCE` INT UNSIGNED,`RESOURCE_NAME` VARCHAR(512),`PAGE_SIZE` INT UNSIGNED,`PAGES_USED` INT UNSIGNED,`PAGES_TOTAL` INT UNSIGNED) ENGINE=NDBINFO;','SET @dummy = 0');
+PREPARE stmt FROM @str;
+EXECUTE stmt;
+DROP PREPARE stmt;
+
+-- ndb$info.LOGDESTINATION
+SET @str=IF(@have_ndbinfo,'DROP TABLE IF EXISTS `ndb$info`.`NDB$LOGDESTINATION`','SET @dummy = 0');
+PREPARE stmt FROM @str;
+EXECUTE stmt;
+DROP PREPARE stmt;
+
+SET @str=IF(@have_ndbinfo,'CREATE TABLE `ndb$info`.`NDB$LOGDESTINATION` (`NODE_ID` INT UNSIGNED,`TYPE` VARCHAR(512),`PARAMS` VARCHAR(512),`CURRENT_SIZE` INT UNSIGNED,`MAX_SIZE` INT UNSIGNED) ENGINE=NDBINFO;','SET @dummy = 0');
+PREPARE stmt FROM @str;
+EXECUTE stmt;
+DROP PREPARE stmt;
+
+-- ndb$info.BACKUP_RECORDS
+SET @str=IF(@have_ndbinfo,'DROP TABLE IF EXISTS `ndb$info`.`NDB$BACKUP_RECORDS`','SET @dummy = 0');
+PREPARE stmt FROM @str;
+EXECUTE stmt;
+DROP PREPARE stmt;
+
+SET @str=IF(@have_ndbinfo,'CREATE TABLE `ndb$info`.`NDB$BACKUP_RECORDS` (`NODE_ID` INT UNSIGNED,`BACKUP_RECORD` INT UNSIGNED,`BACKUP_ID` INT UNSIGNED,`MASTER_REF` INT UNSIGNED,`CLIENT_REF` INT UNSIGNED,`STATE` INT UNSIGNED,`BYTES` INT UNSIGNED,`RECORDS` INT UNSIGNED,`LOG_BYTES` INT UNSIGNED,`LOG_RECORDS` INT UNSIGNED,`ERROR_CODE` INT UNSIGNED) ENGINE=NDBINFO;','SET @dummy = 0');
+PREPARE stmt FROM @str;
+EXECUTE stmt;
+DROP PREPARE stmt;
+
+-- ndb$info.BACKUP_PARAMETERS
+SET @str=IF(@have_ndbinfo,'DROP TABLE IF EXISTS `ndb$info`.`NDB$BACKUP_PARAMETERS`','SET @dummy = 0');
+PREPARE stmt FROM @str;
+EXECUTE stmt;
+DROP PREPARE stmt;
+
+SET @str=IF(@have_ndbinfo,'CREATE TABLE `ndb$info`.`NDB$BACKUP_PARAMETERS` (`NODE_ID` INT UNSIGNED,`CURRENT_DISK_WRITE_SPEED` INT UNSIGNED,`BYTES_WRITTEN_THIS_PERIOD` INT UNSIGNED,`OVERFLOW_DISK_WRITE` INT UNSIGNED,`RESET_DELAY_USED` INT UNSIGNED,`RESET_DISK_SPEED_TIME` INT UNSIGNED,`BACKUP_POOL_SIZE` INT UNSIGNED,`BACKUP_FILE_POOL_SIZE` INT UNSIGNED,`TABLE_POOL_SIZE` INT UNSIGNED,`TRIGGER_POOL_SIZE` INT UNSIGNED,`FRAGMENT_POOL_SIZE` INT UNSIGNED,`PAGE_POOL_SIZE` INT UNSIGNED,`COMPRESSED_BACKUP` INT UNSIGNED,`COMPRESSED_LCP` INT UNSIGNED) ENGINE=NDBINFO;','SET @dummy = 0');
+PREPARE stmt FROM @str;
+EXECUTE stmt;
+DROP PREPARE stmt;
+
+-- ndb$info.POOLS
+SET @str=IF(@have_ndbinfo,'DROP TABLE IF EXISTS `ndb$info`.`NDB$POOLS`','SET @dummy = 0');
+PREPARE stmt FROM @str;
+EXECUTE stmt;
+DROP PREPARE stmt;
+
+SET @str=IF(@have_ndbinfo,'CREATE TABLE `ndb$info`.`NDB$POOLS` (`NODE_ID` INT UNSIGNED,`BLOCK_NUMBER` INT UNSIGNED,`BLOCK_INSTANCE` INT UNSIGNED,`POOL_NAME` VARCHAR(512),`FREE` INT UNSIGNED,`SIZE` INT UNSIGNED) ENGINE=NDBINFO;','SET @dummy = 0');
+PREPARE stmt FROM @str;
+EXECUTE stmt;
+DROP PREPARE stmt;

=== modified file 'sql/ha_ndbinfo.cc'
--- a/sql/ha_ndbinfo.cc	2009-07-08 08:41:40 +0000
+++ b/sql/ha_ndbinfo.cc	2009-07-09 15:04:27 +0000
@@ -17,6 +17,7 @@
 */
 
 #include "mysql_priv.h"
+#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
 #include "ha_ndbinfo.h"
 #include "../storage/ndb/src/ndbapi/NdbInfo.hpp"
 
@@ -50,6 +51,15 @@ static NdbInfo* g_ndbinfo;
 
 extern Ndb_cluster_connection* g_ndb_cluster_connection;
 
+static bool
+ndbcluster_is_disabled(void)
+{
+  if (g_ndb_cluster_connection)
+    return false;
+  assert(g_ndbinfo == NULL);
+  return true;
+}
+
 static handler*
 create_handler(handlerton *hton, TABLE_SHARE *table, MEM_ROOT *mem_root)
 {
@@ -132,13 +142,10 @@ int ha_ndbinfo::open(const char *name, i
     DBUG_ASSERT(false);
   }
 
-  if (!g_ndbinfo)
+  if (ndbcluster_is_disabled())
   {
-    push_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_NOTE, 1,
-                 "Can't open table - 'ndbinfo' has been started "
-                 "in limited mode because the 'ndbcluster' "
-                 "engine is disabled");
-    DBUG_RETURN(HA_ERR_WRONG_COMMAND);
+    // Allow table to be opened with ndbcluster disabled
+    DBUG_RETURN(0);
   }
 
   /* Increase "ref_length" to allow a whole row to be stored in "ref" */
@@ -161,6 +168,10 @@ int ha_ndbinfo::open(const char *name, i
 int ha_ndbinfo::close(void)
 {
   DBUG_ENTER("ha_ndbinfo::close");
+
+  if (ndbcluster_is_disabled())
+    DBUG_RETURN(0);
+
   assert(is_open());
   if (m_impl.m_table)
   {
@@ -174,6 +185,16 @@ int ha_ndbinfo::rnd_init(bool scan)
 {
   DBUG_ENTER("ha_ndbinfo::rnd_init");
   DBUG_PRINT("info", ("scan: %d", scan));
+
+  if (ndbcluster_is_disabled())
+  {
+    push_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_NOTE, 1,
+                 "'NDBINFO' has been started "
+                 "in limited mode since the 'NDBCLUSTER' "
+                 "engine is disabled - no rows can be returned");
+    DBUG_RETURN(0);
+  }
+
   assert(is_open());
   assert(m_impl.m_scan_op == NULL); // No scan already ongoing
 
@@ -217,6 +238,10 @@ int ha_ndbinfo::rnd_init(bool scan)
 int ha_ndbinfo::rnd_end()
 {
   DBUG_ENTER("ha_ndbinfo::rnd_end");
+
+  if (ndbcluster_is_disabled())
+    DBUG_RETURN(0);
+
   assert(is_open());
 
   if (m_impl.m_scan_op)
@@ -233,6 +258,10 @@ int ha_ndbinfo::rnd_next(uchar *buf)
 {
   int err;
   DBUG_ENTER("ha_ndbinfo::rnd_next");
+
+  if (ndbcluster_is_disabled())
+    DBUG_RETURN(HA_ERR_END_OF_FILE);
+
   assert(is_open());
   assert(m_impl.m_scan_op);
 
@@ -304,10 +333,9 @@ ha_ndbinfo::unpack_record(uchar *dst_row
         /* Field_bit in DBUG requires the bit set in write_set for store(). */
         my_bitmap_map *old_map =
           dbug_tmp_use_all_columns(table, table->write_set);
-//        IF_DBUG(int res =)
-                           vfield->store(record->c_str(),
-                                         strlen(record->c_str()),
-                                         field->charset());
+        (void)vfield->store(record->c_str(),
+                            min(record->length(), field->field_length)-1,
+                            field->charset());
         dbug_tmp_restore_column_map(table->write_set, old_map);
         break;
       }
@@ -349,23 +377,25 @@ int ndbinfo_init(void *plugin)
 
   ndbinfo_hton = hton;
 
-  /* Check if 'ndbcluster_init' has been run and connected to cluster */
-  if (!g_ndb_cluster_connection)
+  if (ndbcluster_is_disabled())
   {
-    sql_print_warning("Starting 'ndbinfo' in limited mode "
-                      "because 'ndbcluster' engine is disabled");
+    sql_print_warning("Starting 'NDBINFO' in limited mode "
+                      "since 'NDBCLUSTER' engine is disabled");
 
     DBUG_RETURN(0);
   }
 
+  const char* ndbinfo_db = "ndb$info";
+  const char* table_prefix = "NDB$";
   bool use_lower_case = (lower_case_table_names != 0);
   char prefix[FN_REFLEN];
   build_table_filename(prefix, sizeof(prefix) - 1,
-                                    "ndb$info", "", "", 0);
+                       ndbinfo_db, table_prefix, "", 0);
   DBUG_PRINT("info", ("prefix: '%s', use_lower_case: %d",
                       prefix, use_lower_case));
   assert(g_ndb_cluster_connection);
-  g_ndbinfo = new NdbInfo(g_ndb_cluster_connection, prefix, use_lower_case);
+  g_ndbinfo = new NdbInfo(g_ndb_cluster_connection, prefix,
+                          ndbinfo_db, table_prefix, use_lower_case);
   if (!g_ndbinfo)
   {
     sql_print_error("Failed to create NdbInfo");
@@ -406,3 +436,5 @@ struct st_mysql_sys_var* ndbinfo_system_
 };
 
 template class Vector<const NdbInfoRecAttr*>;
+
+#endif

=== modified file 'storage/ndb/include/util/HashMap.hpp'
--- a/storage/ndb/include/util/HashMap.hpp	2009-06-23 11:49:16 +0000
+++ b/storage/ndb/include/util/HashMap.hpp	2009-07-09 10:37:49 +0000
@@ -164,8 +164,8 @@ public:
     return m_hash.records;
   }
 
-  T* value(size_t i) {
-    Entry* entry = (Entry*)my_hash_element(&m_hash, i);
+  T* value(size_t i) const {
+    Entry* entry = (Entry*)my_hash_element((HASH*)&m_hash, i);
     if (entry == NULL)
       return NULL;
     return &(entry->m_value);

=== modified file 'storage/ndb/src/kernel/blocks/dbinfo/Dbinfo.cpp'
--- a/storage/ndb/src/kernel/blocks/dbinfo/Dbinfo.cpp	2009-07-03 14:54:34 +0000
+++ b/storage/ndb/src/kernel/blocks/dbinfo/Dbinfo.cpp	2009-07-09 10:37:49 +0000
@@ -108,12 +108,10 @@ void Dbinfo::execDUMP_STATE_ORD(Signal* 
   case DumpStateOrd::DbinfoListTables:
     jam();
     ndbout_c("--- BEGIN NDB$INFO.TABLES ---");
-    char create_sql[512];
     for(int i = 0; i < Ndbinfo::getNumTables(); i++)
     {
       const Ndbinfo::Table& tab = Ndbinfo::getTable(i);
-      Ndbinfo::create_sql(tab, create_sql, sizeof(create_sql));
-      ndbout_c("%d,%s,%s", i, tab.m.name, create_sql);
+      ndbout_c("%d,%s", i, tab.m.name);
     }
     ndbout_c("--- END NDB$INFO.TABLES ---");
     break;
@@ -270,7 +268,6 @@ void Dbinfo::execDBINFO_SCANREQ(Signal *
     jam();
 
     Ndbinfo::Ratelimit rl;
-    char create_sql[512];
     Uint32 tableId = cursor->data[0];
 
     while(tableId < (Uint32)Ndbinfo::getNumTables())
@@ -278,10 +275,8 @@ void Dbinfo::execDBINFO_SCANREQ(Signal *
       jam();
       const Ndbinfo::Table& tab = Ndbinfo::getTable(tableId);
       Ndbinfo::Row row(signal, req);
-      Ndbinfo::create_sql(tab, create_sql, sizeof(create_sql));
       row.write_uint32(tableId);
       row.write_string(tab.m.name);
-      row.write_string(create_sql);
       ndbinfo_send_row(signal, req, row, rl);
 
       tableId++;
@@ -321,7 +316,7 @@ void Dbinfo::execDBINFO_SCANREQ(Signal *
         row.write_uint32(tableId);
         row.write_uint32(columnId);
         row.write_string(tab.col[columnId].name);
-        row.write_string(Ndbinfo::coltype_to_string(tab.col[columnId].coltype));
+        row.write_uint32(tab.col[columnId].coltype);
         ndbinfo_send_row(signal, req, row, rl);
 
         assert(columnId < 256);

=== modified file 'storage/ndb/src/kernel/vm/Ndbinfo.cpp'
--- a/storage/ndb/src/kernel/vm/Ndbinfo.cpp	2009-07-03 10:31:30 +0000
+++ b/storage/ndb/src/kernel/vm/Ndbinfo.cpp	2009-07-09 10:37:49 +0000
@@ -110,13 +110,11 @@ static const struct  {                  
 } var
 
 
-/** Reserved for DBINFO only */
-DECLARE_NDBINFO_TABLE(ndbinfo_TABLES,3) =
-{ "TABLES", 3, 0,
+DECLARE_NDBINFO_TABLE(ndbinfo_TABLES,2) =
+{ "TABLES", 2, 0,
   {
     {"TABLE_ID",  Ndbinfo::Number},
     {"TABLE_NAME",Ndbinfo::String},
-    {"CREATE_SQL",Ndbinfo::String},
   }};
 
 /** Reserved for DBINFO only */
@@ -126,7 +124,7 @@ DECLARE_NDBINFO_TABLE(ndbinfo_COLUMNS,4)
     {"TABLE_ID",    Ndbinfo::Number},
     {"COLUMN_ID",   Ndbinfo::Number},
     {"COLUMN_NAME", Ndbinfo::String},
-    {"COLUMN_TYPE", Ndbinfo::String},
+    {"COLUMN_TYPE", Ndbinfo::Number},
   }};
 
 DECLARE_NDBINFO_TABLE(ndbinfo_MEMUSAGE,7) =
@@ -243,49 +241,5 @@ const Ndbinfo::Table& Ndbinfo::getTable(
   return getTable((int)i);
 }
 
-int
-Ndbinfo::create_sql(const Ndbinfo::Table& tab,
-                    char* sql, int len,
-                    const char* line_separator)
-{
-  my_snprintf(sql,len,"CREATE TABLE `%s` (", tab.m.name);
-
-  len-=strlen(sql);
-  sql+=strlen(sql);
-  if(len<0)
-    return ENOMEM;
-
-  for(int i = 0; i < tab.m.ncols; i++)
-  {
-    my_snprintf(sql, len, "%s\t`%s` %s,",
-                line_separator, tab.col[i].name,
-                coltype_to_string(tab.col[i].coltype));
-    len-=strlen(sql);
-    sql+=strlen(sql);
-    if(len<0)
-      return ENOMEM;
-  }
-  *(--sql)='\0';
-  my_snprintf(sql,len,"%s) ENGINE=NDBINFO;", line_separator);
-  len-=strlen(sql);
-  sql+=strlen(sql);
-  if(len<0)
-    return ENOMEM;
-
-  return 0;
-}
-
-const char*
-Ndbinfo::coltype_to_string(ColumnType coltype) {
-  static const char* type_string[]= {"NONE",
-                                     "VARCHAR(512)",
-                                     "INT UNSIGNED"
-  };
-
-  if(coltype>3)
-    coltype= (ColumnType)0;
-
-  return type_string[coltype];
-}
 
 

=== modified file 'storage/ndb/src/kernel/vm/Ndbinfo.hpp'
--- a/storage/ndb/src/kernel/vm/Ndbinfo.hpp	2009-07-03 10:31:30 +0000
+++ b/storage/ndb/src/kernel/vm/Ndbinfo.hpp	2009-07-09 10:37:49 +0000
@@ -34,8 +34,6 @@ public:
     ColumnType coltype;
   };
 
-  static const char* coltype_to_string(ColumnType coltype);
-
   enum TableId {
     TABLES_TABLEID =             0,
     COLUMNS_TABLEID =            1,
@@ -62,8 +60,6 @@ public:
   static int getNumTables();
   static const Table& getTable(int i);
   static const Table& getTable(Uint32 i);
-  static int create_sql(const Table& t, char* sql, int len,
-                        const char* line_separator = "\n");
 
   class Row {
     friend class SimulatedBlock;

=== modified file 'storage/ndb/src/ndbapi/NdbInfo.cpp'
--- a/storage/ndb/src/ndbapi/NdbInfo.cpp	2009-07-07 09:10:02 +0000
+++ b/storage/ndb/src/ndbapi/NdbInfo.cpp	2009-07-09 15:04:27 +0000
@@ -21,11 +21,15 @@
 #include <ndbapi/ndb_cluster_connection.hpp>
 
 NdbInfo::NdbInfo(class Ndb_cluster_connection* connection,
-                 const char* prefix, bool use_lower_case) :
+                 const char* prefix, const char* dbname,
+                 const char* table_prefix,
+                 bool use_lower_case) :
   m_connect_count(connection->get_connect_count()),
   m_connection(connection),
   m_tables_table(NULL), m_columns_table(NULL),
   m_prefix(prefix),
+  m_dbname(dbname),
+  m_table_prefix(table_prefix),
   m_use_lower_case(use_lower_case),
   m_id_counter(0)
 {
@@ -60,10 +64,10 @@ BaseString NdbInfo::mysql_table_name(con
 bool NdbInfo::load_hardcoded_tables(void)
 {
   {
-    InfoTable tabs("TABLES", 0, "");
+    InfoTable tabs("TABLES", 0);
     if (!tabs.addColumn(InfoColumn("TABLE_ID", 0, InfoColumn::Number)) ||
         !tabs.addColumn(InfoColumn("TABLE_NAME", 1, InfoColumn::String)) ||
-        !tabs.addColumn(InfoColumn("CREATE_SQL", 2, InfoColumn::String)))
+        !tabs.addColumn(InfoColumn("CREATE_SQL", 2, InfoColumn::String, true)))
       return false;
 
     BaseString hash_key = mysql_table_name(tabs.getName());
@@ -74,7 +78,7 @@ bool NdbInfo::load_hardcoded_tables(void
   }
 
   {
-    InfoTable cols("COLUMNS", 1, "");
+    InfoTable cols("COLUMNS", 1);
     if (!cols.addColumn(InfoColumn("TABLE_ID", 0, InfoColumn::Number)) ||
         !cols.addColumn(InfoColumn("COLUMN_ID", 1, InfoColumn::Number)) ||
         !cols.addColumn(InfoColumn("COLUMN_NAME", 2, InfoColumn::String)) ||
@@ -127,8 +131,7 @@ bool NdbInfo::load_ndbinfo_tables(void)
 
     const NdbInfoRecAttr *tableIdRes = scanOp->getValue("TABLE_ID");
     const NdbInfoRecAttr *tableNameRes = scanOp->getValue("TABLE_NAME");
-    const NdbInfoRecAttr *createSQLRes = scanOp->getValue("CREATE_SQL");
-    if (!tableIdRes || !tableNameRes || !createSQLRes)
+    if (!tableIdRes || !tableNameRes)
     {
       releaseScanOperation(scanOp);
       DBUG_RETURN(false);
@@ -145,28 +148,23 @@ bool NdbInfo::load_ndbinfo_tables(void)
     {
       Uint32 tableId = tableIdRes->u_32_value();
       const char * tableName = tableNameRes->c_str();
-      const char * createSQL = createSQLRes->c_str();
-      DBUG_PRINT("info", ("table: '%s', id: %u, sql: '%s'",
-                 tableName, tableId, createSQL));
+      DBUG_PRINT("info", ("table: '%s', id: %u",
+                 tableName, tableId));
       switch (tableId) {
       case 0:
-        // Save SQL for TABLES table
         assert(strcmp(tableName, "TABLES") == 0);
-        m_tables_table->setCreateSQL(createSQL);
         break;
       case 1:
-        // Save SQL for COLUMNS table
         assert(strcmp(tableName, "COLUMNS") == 0);
-        m_columns_table->setCreateSQL(createSQL);
         break;
 
       default:
         BaseString hash_key = mysql_table_name(tableName);
         if (!m_tables.insert(hash_key.c_str(),
-                             InfoTable(tableName, tableId, createSQL)))
+                             InfoTable(tableName, tableId)))
         {
-          DBUG_PRINT("error", ("Failed to insert InfoTable('%s', %u, '%s')",
-                     tableName, tableId, createSQL));
+          DBUG_PRINT("error", ("Failed to insert InfoTable('%s', %u)",
+                     tableName, tableId));
           releaseScanOperation(scanOp);
           DBUG_RETURN(false);
         }
@@ -211,9 +209,9 @@ bool NdbInfo::load_ndbinfo_tables(void)
       Uint32 tableId = tableIdRes->u_32_value();
       Uint32 columnId = columnIdRes->u_32_value();
       const char * columnName = columnNameRes->c_str();
-      const char * columnType = columnTypeRes->c_str();
+      Uint32 columnType = columnTypeRes->u_32_value();
       DBUG_PRINT("info",
-                 ("tableId: %u, columnId: %u, column: '%s', type: '%s'",
+                 ("tableId: %u, columnId: %u, column: '%s', type: %d",
                  tableId, columnId, columnName, columnType));
       switch (tableId) {
       case 0:
@@ -225,16 +223,21 @@ bool NdbInfo::load_ndbinfo_tables(void)
       default:
       {
         InfoColumn::Type type;
-        if (strcmp(columnType, "INT UNSIGNED") == 0)
-          type = InfoColumn::Number;
-        else if (strcmp(columnType, "VARCHAR(512)") == 0)
+        switch(columnType)
+        {
+        case 1:
           type = InfoColumn::String;
-        else
+          break;
+        case 2:
+          type = InfoColumn::Number;
+          break;
+        default:
         {
-          DBUG_PRINT("error", ("Unknown columntype: '%s'", columnType));
+          DBUG_PRINT("error", ("Unknown columntype: %d", columnType));
           releaseScanOperation(scanOp);
           DBUG_RETURN(false);
         }
+        }
 
         InfoColumn column(columnName, columnId, type);
 
@@ -242,7 +245,7 @@ bool NdbInfo::load_ndbinfo_tables(void)
 
         if (!addColumn(tableId, column))
         {
-          DBUG_PRINT("error", ("Failed to add column for %d, %d, '%s', '%s')",
+          DBUG_PRINT("error", ("Failed to add column for %d, %d, '%s', %d)",
                      tableId, columnId, columnName, columnType));
           releaseScanOperation(scanOp);
           DBUG_RETURN(false);
@@ -259,6 +262,52 @@ bool NdbInfo::load_ndbinfo_tables(void)
   DBUG_RETURN(true);
 }
 
+BaseString NdbInfo::InfoTable::generateSQL(const char* dbname,
+                                           const char* table_prefix,
+                                           const char* line_separator,
+                                           const char* tab_separator) const
+{
+  BaseString sql;
+  sql.assfmt("CREATE TABLE `%s`.`%s%s` (", dbname, table_prefix, getName());
+
+  for(unsigned i = 0; i < columns(); i++)
+  {
+    const NdbInfo::InfoColumn* col = getColumn(i);
+    sql.appfmt("%s%s`%s` %s%s",
+               line_separator,
+               tab_separator,
+               col->m_name.c_str(),
+               col->getSQLType(),
+               i+1 < columns() ? "," : "");
+  }
+
+  sql.appfmt("%s) ENGINE=NDBINFO;", line_separator);
+  return sql;
+}
+
+void NdbInfo::generateSQL(void)
+{
+  for (size_t i = 0; i < m_tables.entries(); i++)
+  {
+    InfoTable* tab = m_tables.value(i);
+    tab->m_sql = tab->generateSQL(m_dbname.c_str(),
+                                  m_table_prefix.c_str());
+  }
+}
+
+
+const char* NdbInfo::getCreateSQL(Uint32 tableId) const
+{
+  for (size_t i = 0; i < m_tables.entries(); i++)
+  {
+    const InfoTable* tmp = m_tables.value(i);
+    if (tmp->m_table_id == tableId)
+      return tmp->getCreateSQL();
+  }
+  return "<unknown SQL>";
+}
+
+
 bool NdbInfo::load_tables()
 {
   if (!load_ndbinfo_tables())
@@ -268,6 +317,8 @@ bool NdbInfo::load_tables()
     return false;
   }
 
+  generateSQL();
+
   // After sucessfull load of the tables, set connect count
   m_connect_count = m_connection->get_connect_count();
   return true;
@@ -277,7 +328,7 @@ int NdbInfo::createScanOperation(const I
                                  NdbInfoScanOperation** ret_scan_op,
                                  Uint32 max_rows, Uint32 max_bytes)
 {
-  NdbInfoScanOperation* scan_op = new NdbInfoScanOperation(m_connection,
+  NdbInfoScanOperation* scan_op = new NdbInfoScanOperation(*this, m_connection,
                                                            table, max_rows,
                                                            max_bytes);
   if (!scan_op)
@@ -401,10 +452,12 @@ void NdbInfo::closeTable(const InfoTable
 // InfoColumn
 
 NdbInfo::InfoColumn::InfoColumn(const char* name, Uint32 col_id,
-                                NdbInfo::InfoColumn::Type type) :
+                                NdbInfo::InfoColumn::Type type,
+                                bool local) :
   m_type(type),
   m_column_id(col_id),
-  m_name(name)
+  m_name(name),
+  m_local(local)
 {
 }
 
@@ -413,6 +466,7 @@ NdbInfo::InfoColumn::InfoColumn(const Nd
   m_column_id = col.m_column_id;
   m_name.assign(col.m_name);
   m_type = col.m_type;
+  m_local = col.m_local;
 }
 
 NdbInfo::InfoColumn &
@@ -421,15 +475,30 @@ NdbInfo::InfoColumn::operator=(const Ndb
   m_column_id = col.m_column_id;
   m_name.assign(col.m_name);
   m_type = col.m_type;
+  m_local = col.m_local;
   return *this;
 }
 
+const char*
+NdbInfo::InfoColumn::getSQLType() const {
+  switch(m_type)
+  {
+  case Number:
+    return "INT UNSIGNED";
+  case String:
+    return "VARCHAR(512)";
+  default:
+    assert(false);
+    break;
+  }
+  return "NONE";
+}
+
+
 // InfoTable
 
-NdbInfo::InfoTable::InfoTable(const char *name, Uint32 id,
-                              const char* create_sql) :
+NdbInfo::InfoTable::InfoTable(const char *name, Uint32 id) :
   m_name(name),
-  m_create_sql(create_sql),
   m_table_id(id)
 {
 };
@@ -439,7 +508,7 @@ NdbInfo::InfoTable::InfoTable(const NdbI
   DBUG_ENTER("InfoTable(const InfoTable&");
   m_table_id = tab.m_table_id;
   m_name.assign(tab.m_name);
-  m_create_sql.assign(tab.m_create_sql);
+  m_sql.assign(tab.m_sql);
   for (unsigned i = 0; i < tab.m_columns.size(); i++)
     addColumn(*tab.m_columns[i]);
   DBUG_VOID_RETURN;
@@ -451,7 +520,7 @@ NdbInfo::InfoTable::operator=(const NdbI
   DBUG_ENTER("InfoTable::operator=");
   m_table_id = tab.m_table_id;
   m_name.assign(tab.m_name);
-  m_create_sql.assign(tab.m_create_sql);
+  m_sql.assign(tab.m_sql);
   for (unsigned i = 0; i < tab.m_columns.size(); i++)
     addColumn(*tab.m_columns[i]);
   DBUG_RETURN(*this);
@@ -470,12 +539,7 @@ const char * NdbInfo::InfoTable::getName
 
 const char * NdbInfo::InfoTable::getCreateSQL() const
 {
-  return m_create_sql.c_str();
-}
-
-void NdbInfo::InfoTable::setCreateSQL(const char* create_sql)
-{
-  m_create_sql.assign(create_sql);
+  return m_sql.c_str();
 }
 
 Uint32 NdbInfo::InfoTable::getTableId() const

=== modified file 'storage/ndb/src/ndbapi/NdbInfo.hpp'
--- a/storage/ndb/src/ndbapi/NdbInfo.hpp	2009-07-03 10:31:30 +0000
+++ b/storage/ndb/src/ndbapi/NdbInfo.hpp	2009-07-09 10:37:49 +0000
@@ -45,48 +45,59 @@ public:
 
     enum Type
     {
-      Number,
-      String
+      Number = 1,
+      String = 2
     } m_type;
 
     Uint32 m_column_id;
     BaseString m_name;
 
-    InfoColumn(const char* name, Uint32 col_id, Type type);
+    InfoColumn(const char* name, Uint32 col_id, Type type, bool local = false);
     InfoColumn(const InfoColumn & col);
     InfoColumn & operator=(const InfoColumn & col);
+
+    const char* getSQLType() const;
+
+    bool is_local() const { return m_local; }
+
+  private:
+    bool m_local;
   };
 
   class InfoTable
   {
   public:
 
-    InfoTable(const char *name, Uint32 id, const char* create_sql);
+    InfoTable(const char *name, Uint32 id);
     InfoTable(const InfoTable& tab);
     const InfoTable & operator=(const InfoTable& tab);
     ~InfoTable();
 
     const char * getName() const;
     Uint32 getTableId() const;
-
     const char * getCreateSQL() const;
-    void setCreateSQL(const char* create_sql);
 
     bool addColumn(const InfoColumn aCol);
     unsigned columns(void) const;
     const InfoColumn* getColumn(const unsigned attributeId) const;
     const InfoColumn* getColumn(const char * name) const;
 
+    BaseString generateSQL(const char* dbname,
+                           const char* table_prefix,
+                           const char* line_separator = "\n",
+                           const char* tab_separator = "\t") const;
+
   private:
     friend class NdbInfo;
     BaseString m_name;
-    BaseString m_create_sql;
+    BaseString m_sql;
     Uint32 m_table_id;
     Vector<InfoColumn*> m_columns;
   };
 
   NdbInfo(class Ndb_cluster_connection* connection,
-          const char* prefix, bool use_lower_case = false);
+          const char* prefix, const char* dbname = "",
+          const char* table_prefix = "", bool use_lower_case = false);
   bool init(void);
   ~NdbInfo();
 
@@ -101,6 +112,8 @@ public:
                           Uint32 max_rows = 256, Uint32 max_bytes = 0);
   void releaseScanOperation(class NdbInfoScanOperation*) const;
 
+  const char* getCreateSQL(Uint32 tableId) const;
+
 private:
   static const size_t NUM_HARDCODED_TABLES = 2;
   unsigned m_connect_count;
@@ -110,6 +123,8 @@ private:
   InfoTable* m_tables_table;
   InfoTable* m_columns_table;
   BaseString m_prefix;
+  BaseString m_dbname;
+  BaseString m_table_prefix;
   bool m_use_lower_case;
   Uint32 m_id_counter;
 
@@ -119,6 +134,7 @@ private:
   bool load_hardcoded_tables(void);
   bool load_tables();
   bool check_tables();
+  void generateSQL(void);
 
   BaseString mysql_table_name(const char* table_name) const;
 

=== modified file 'storage/ndb/src/ndbapi/NdbInfoScanOperation.cpp'
--- a/storage/ndb/src/ndbapi/NdbInfoScanOperation.cpp	2009-07-03 21:49:24 +0000
+++ b/storage/ndb/src/ndbapi/NdbInfoScanOperation.cpp	2009-07-09 10:37:49 +0000
@@ -27,9 +27,11 @@
 // CAST_PTR
 #include "NdbApiSignal.hpp"
 
-NdbInfoScanOperation::NdbInfoScanOperation(Ndb_cluster_connection* connection,
+NdbInfoScanOperation::NdbInfoScanOperation(const NdbInfo& info,
+                                           Ndb_cluster_connection* connection,
                                            const NdbInfo::InfoTable* table,
                                            Uint32 max_rows, Uint32 max_bytes) :
+  m_info(info),
   m_state(Undefined),
   m_connection(connection),
   m_signal_sender(NULL),
@@ -305,6 +307,36 @@ NdbInfoScanOperation::execDBINFO_TRANSID
   DBUG_PRINT("info", ("start: %p, end: %p", start, end));
   for (unsigned col = 0; col < m_table->columns(); col++)
   {
+    const NdbInfo::InfoColumn* column =  m_table->getColumn(col);
+    if (column->is_local())
+    {
+      // The data for this column is generated locally
+      // in the API
+      NdbInfoRecAttr* attr = m_recAttrs[col];
+      if (!attr)
+        continue;
+
+      if (strcmp(m_table->getName(), "TABLES") == 0 &&
+          strcmp(column->m_name.c_str(), "CREATE_SQL") == 0)
+      {
+        // Read tableId
+        const Uint32 *ptr = signal->ptr[0].p;
+        const AttributeHeader ah(*ptr);
+        assert(ah.getByteSize() == sizeof(Uint32));
+        // Step past attribute header
+        ptr += ah.getHeaderSize();
+        const Uint32 tableId = *ptr;
+        attr->m_data = m_info.getCreateSQL(tableId);
+      }
+      else
+      {
+        // Unknown local column!
+        attr->m_data = "<unknown local column>";
+      }
+      attr->m_len = strlen(attr->m_data)+1;
+      continue;
+    }
+
     // Read attribute header
     const AttributeHeader ah(*start);
     const Uint32 len = ah.getByteSize();

=== modified file 'storage/ndb/src/ndbapi/NdbInfoScanOperation.hpp'
--- a/storage/ndb/src/ndbapi/NdbInfoScanOperation.hpp	2009-07-03 10:31:30 +0000
+++ b/storage/ndb/src/ndbapi/NdbInfoScanOperation.hpp	2009-07-09 10:37:49 +0000
@@ -28,7 +28,8 @@ public:
   int nextResult();
 protected:
   friend class NdbInfo;
-  NdbInfoScanOperation(class Ndb_cluster_connection*,
+  NdbInfoScanOperation(const NdbInfo&,
+                       class Ndb_cluster_connection*,
                        const NdbInfo::InfoTable*,
                        Uint32 max_rows, Uint32 max_bytes);
   bool init(Uint32 id);
@@ -42,6 +43,7 @@ private:
 
   int receive(void);
 
+  const NdbInfo& m_info;
   enum State { Undefined, Initial, Prepared,
                MoreData, End, Error } m_state;
   class Ndb_cluster_connection* m_connection;

=== modified file 'storage/ndb/test/ndbapi/testNdbinfo.cpp'
--- a/storage/ndb/test/ndbapi/testNdbinfo.cpp	2009-07-03 10:31:30 +0000
+++ b/storage/ndb/test/ndbapi/testNdbinfo.cpp	2009-07-09 15:04:27 +0000
@@ -75,6 +75,75 @@ int runTestNdbInfo(NDBT_Context* ctx, ND
 }
 
 
+int runCreateSQL(NDBT_Context* ctx, NDBT_Step* step)
+{
+  const char* ndbinfo_db = "ndb$info";
+  const char* table_prefix = "NDB$";
+
+  NdbInfo ndbinfo(&ctx->m_cluster_connection, "ndbinfo/",
+                  ndbinfo_db, table_prefix);
+  if (!ndbinfo.init())
+  {
+    g_err << "ndbinfo.init failed" << endl;
+    return NDBT_FAILED;
+  }
+
+  fprintf(stdout, "--\n");
+  fprintf(stdout, "-- %s tables\n", ndbinfo_db);
+  fprintf(stdout, "--\n");
+  fprintf(stdout, "-- Always create %s database\n", ndbinfo_db);
+  fprintf(stdout, "CREATE DATABASE IF NOT EXISTS `%s`;\n\n", ndbinfo_db);
+
+  fprintf(stdout, "-- Only create tables if NDBINFO is enabled\n");
+  fprintf(stdout, "SELECT @have_ndbinfo:= COUNT(*) FROM "
+                  "information_schema.engines WHERE engine='NDBINFO' "
+                  "AND support IN ('YES', 'DEFAULT');\n\n");
+
+  Uint32 tableId = 0;
+  while(true) {
+    const NdbInfo::InfoTable* table;
+
+    int err = ndbinfo.openTable(tableId, &table);
+    if (err == NdbInfo::ERR_NoSuchTable)
+    {
+      // No more tables
+      break;
+    }
+    else if (err != 0)
+    {
+      // Unexpected return code
+      g_err << "Failed to openTable(" << tableId << "), err: " << err << endl;
+      return NDBT_FAILED;
+    }
+
+    fprintf(stdout, "-- %s.%s\n", ndbinfo_db, table->getName());
+
+    /* Drop the table if it exists */
+    fprintf(stdout, "SET @str=IF(@have_ndbinfo,"
+                    "'DROP TABLE IF EXISTS `%s`.`%s%s`',"
+                    "'SET @dummy = 0');\n",
+            ndbinfo_db, table_prefix, table->getName());
+    fprintf(stdout, "PREPARE stmt FROM @str;\n");
+    fprintf(stdout, "EXECUTE stmt;\n");
+    fprintf(stdout, "DROP PREPARE stmt;\n\n");
+
+    /* Create the table */
+    BaseString sql = table->generateSQL(ndbinfo_db, table_prefix, "", "");
+
+    fprintf(stdout, "SET @str=IF(@have_ndbinfo,'%s','SET @dummy = 0');\n",
+            sql.c_str());
+    fprintf(stdout, "PREPARE stmt FROM @str;\n");
+    fprintf(stdout, "EXECUTE stmt;\n");
+    fprintf(stdout, "DROP PREPARE stmt;\n\n");
+
+    ndbinfo.closeTable(table);
+    tableId++;
+  }
+
+  return 0;
+}
+
+
 int runScanAll(NDBT_Context* ctx, NDBT_Step* step)
 {
   NdbInfo ndbinfo(&ctx->m_cluster_connection, "ndbinfo/");
@@ -400,6 +469,10 @@ TESTCASE("TestTable",
           "of rows which will depend on how many TUP blocks are configured"){
   STEP(runTestTable);
 }
+TESTCASE("CreateSQL",
+         "Generate the bootstrap SQL"){
+  INITIALIZER(runCreateSQL);
+}
 NDBT_TESTSUITE_END(testNdbinfo);
 
 

Attachment: [text/bzr-bundle] bzr/magnus.blaudd@sun.com-20090709151131-rlwjuidxeyof48x9.bundle
Thread
bzr commit into mysql-5.1-telco-7.1 branch (magnus.blaudd:2939)Magnus Blåudd9 Jul