WL#1190 preparatory work needed for compatability with future online add column

parent 5c2138f5
...@@ -57,6 +57,7 @@ Number of primary keys: 3 ...@@ -57,6 +57,7 @@ Number of primary keys: 3
Length of frm data: # Length of frm data: #
Row Checksum: 1 Row Checksum: 1
Row GCI: 1 Row GCI: 1
ForceVarPart: 1
TableStatus: Retrieved TableStatus: Retrieved
-- Attributes -- -- Attributes --
a Int PRIMARY KEY AT=FIXED ST=MEMORY a Int PRIMARY KEY AT=FIXED ST=MEMORY
......
DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7;
drop database if exists mysqltest;
CREATE TABLE t1
( a INT KEY,
b VARCHAR(10) )
ROW_FORMAT=FIXED
ENGINE=NDB;
ERROR HY000: Can't create table 'test.t1' (errno: 138)
SHOW WARNINGS;
Level Code Message
Error 1466 Table storage engine 'ndbcluster' does not support the create option 'Row format FIXED incompatible with variable sized attributes'
Error 1005 Can't create table 'test.t1' (errno: 138)
CREATE TABLE t1
( a INT KEY,
b INT )
ENGINE=NDB;
ForceVarPart: 1
DROP TABLE t1;
CREATE TABLE t1
( a INT KEY,
b INT )
ROW_FORMAT=DEFAULT
ENGINE=NDB;
ForceVarPart: 1
DROP TABLE t1;
CREATE TABLE t1
( a INT KEY,
b INT )
ROW_FORMAT=FIXED
ENGINE=NDB;
ForceVarPart: 0
DROP TABLE t1;
CREATE TABLE t1
( a INT KEY,
b INT )
ROW_FORMAT=DYNAMIC
ENGINE=NDB;
ForceVarPart: 1
DROP TABLE t1;
-- source include/have_ndb.inc
-- source include/not_embedded.inc
--disable_warnings
DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7;
drop database if exists mysqltest;
--enable_warnings
#
# some negative tests
#
# cannot have ROW_FORMAT=FIXED and var attrs mixed
--error 1005
CREATE TABLE t1
( a INT KEY,
b VARCHAR(10) )
ROW_FORMAT=FIXED
ENGINE=NDB;
# warnings give more detail on the error
SHOW WARNINGS;
#
# Check force var part for different ROW_FORMAT
#
# default => ForceVarPart: 1
CREATE TABLE t1
( a INT KEY,
b INT )
ENGINE=NDB;
--exec $NDB_TOOLS_DIR/ndb_desc --no-defaults -d test t1 | grep ForceVarPart
DROP TABLE t1;
# explicit DEFAULT => ForceVarPart: 1
CREATE TABLE t1
( a INT KEY,
b INT )
ROW_FORMAT=DEFAULT
ENGINE=NDB;
--exec $NDB_TOOLS_DIR/ndb_desc --no-defaults -d test t1 | grep ForceVarPart
DROP TABLE t1;
# FIXED => ForceVarPart: 0
CREATE TABLE t1
( a INT KEY,
b INT )
ROW_FORMAT=FIXED
ENGINE=NDB;
--exec $NDB_TOOLS_DIR/ndb_desc --no-defaults -d test t1 | grep ForceVarPart
DROP TABLE t1;
# DYNAMIC => ForceVarPart: 1
CREATE TABLE t1
( a INT KEY,
b INT )
ROW_FORMAT=DYNAMIC
ENGINE=NDB;
--exec $NDB_TOOLS_DIR/ndb_desc --no-defaults -d test t1 | grep ForceVarPart
DROP TABLE t1;
...@@ -647,6 +647,26 @@ static bool ndb_supported_type(enum_field_types type) ...@@ -647,6 +647,26 @@ static bool ndb_supported_type(enum_field_types type)
#endif /* !DBUG_OFF */ #endif /* !DBUG_OFF */
/*
Check if MySQL field type forces var part in ndb storage
*/
static bool field_type_forces_var_part(enum_field_types type)
{
switch (type) {
case MYSQL_TYPE_VAR_STRING:
case MYSQL_TYPE_VARCHAR:
return TRUE;
case MYSQL_TYPE_TINY_BLOB:
case MYSQL_TYPE_BLOB:
case MYSQL_TYPE_MEDIUM_BLOB:
case MYSQL_TYPE_LONG_BLOB:
case MYSQL_TYPE_GEOMETRY:
return FALSE;
default:
return FALSE;
}
}
/* /*
Instruct NDB to set the value of the hidden primary key Instruct NDB to set the value of the hidden primary key
*/ */
...@@ -4862,6 +4882,28 @@ int ha_ndbcluster::create(const char *name, ...@@ -4862,6 +4882,28 @@ int ha_ndbcluster::create(const char *name,
create_info->storage_media = HA_SM_DISK; //if use tablespace, that also means store on disk create_info->storage_media = HA_SM_DISK; //if use tablespace, that also means store on disk
} }
/*
Handle table row type
Default is to let table rows have var part reference so that online
add column can be performed in the future. Explicitly setting row
type to fixed will omit var part reference, which will save data
memory in ndb, but at the cost of not being able to online add
column to this table
*/
switch (create_info->row_type) {
case ROW_TYPE_FIXED:
tab.setForceVarPart(FALSE);
break;
case ROW_TYPE_DYNAMIC:
/* fall through, treat as default */
default:
/* fall through, treat as default */
case ROW_TYPE_DEFAULT:
tab.setForceVarPart(TRUE);
break;
}
/* /*
Setup columns Setup columns
*/ */
...@@ -4879,6 +4921,28 @@ int ha_ndbcluster::create(const char *name, ...@@ -4879,6 +4921,28 @@ int ha_ndbcluster::create(const char *name,
else else
col.setStorageType(NdbDictionary::Column::StorageTypeMemory); col.setStorageType(NdbDictionary::Column::StorageTypeMemory);
switch (create_info->row_type) {
case ROW_TYPE_FIXED:
if (field_type_forces_var_part(field->type()))
{
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
ER_ILLEGAL_HA_CREATE_OPTION,
ER(ER_ILLEGAL_HA_CREATE_OPTION),
ndbcluster_hton_name,
"Row format FIXED incompatible with "
"variable sized attribute");
DBUG_RETURN(HA_ERR_UNSUPPORTED);
}
break;
case ROW_TYPE_DYNAMIC:
/*
Future: make columns dynamic in this case
*/
break;
default:
break;
}
tab.addColumn(col); tab.addColumn(col);
if (col.getPrimaryKey()) if (col.getPrimaryKey())
pk_length += (field->pack_length() + 3) / 4; pk_length += (field->pack_length() + 3) / 4;
......
...@@ -33,6 +33,7 @@ operator <<(class NdbOut& ndbout, const NDBT_Table & tab) ...@@ -33,6 +33,7 @@ operator <<(class NdbOut& ndbout, const NDBT_Table & tab)
ndbout << "Length of frm data: " << tab.getFrmLength() << endl; ndbout << "Length of frm data: " << tab.getFrmLength() << endl;
ndbout << "Row Checksum: " << tab.getRowChecksumIndicator() << endl; ndbout << "Row Checksum: " << tab.getRowChecksumIndicator() << endl;
ndbout << "Row GCI: " << tab.getRowGCIIndicator() << endl; ndbout << "Row GCI: " << tab.getRowGCIIndicator() << endl;
ndbout << "ForceVarPart: " << tab.getForceVarPart() << endl;
//<< ((tab.getTupleKey() == TupleId) ? " tupleid" : "") <<endl; //<< ((tab.getTupleKey() == TupleId) ? " tupleid" : "") <<endl;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment