From 1aa81f3818023eaf95b46b795a7c4222850e46d1 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 28 Oct 2004 15:35:06 +0000 Subject: [PATCH] test that attribute name truncation works exposed the attribute name size limit for handler added field name truncation to ndb handler mysql-test/t/ndb_basic.test: test that attribute name truncation works ndb/include/ndbapi/ndbapi_limits.h: exposed the attribute name size limit for handler sql/ha_ndbcluster.cc: added field name truncation to ndb handler --- mysql-test/t/ndb_basic.test | 15 +++++++++++++++ ndb/include/ndbapi/ndbapi_limits.h | 1 + sql/ha_ndbcluster.cc | 21 ++++++++++++++++++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/mysql-test/t/ndb_basic.test b/mysql-test/t/ndb_basic.test index 0d4bffce80d..f5bed3dcdff 100644 --- a/mysql-test/t/ndb_basic.test +++ b/mysql-test/t/ndb_basic.test @@ -507,3 +507,18 @@ c127 int, c128 int, primary key(c1)) engine=ndb; drop table t1; + +# +# test max size of attribute name and truncation +# + +create table t1 ( +a1234567890123456789012345678901234567890 int primary key, +a12345678901234567890123456789a1234567890 int, +index(a12345678901234567890123456789a1234567890) +) engine=ndb; +show tables; +insert into t1 values (1,1),(2,1),(3,1),(4,1),(5,2),(6,1),(7,1); +explain select * from t1 where a12345678901234567890123456789a1234567890=2; +select * from t1 where a12345678901234567890123456789a1234567890=2; +drop table t1; diff --git a/ndb/include/ndbapi/ndbapi_limits.h b/ndb/include/ndbapi/ndbapi_limits.h index b3577119e33..05556ab2f5f 100644 --- a/ndb/include/ndbapi/ndbapi_limits.h +++ b/ndb/include/ndbapi/ndbapi_limits.h @@ -22,6 +22,7 @@ #define NDB_MAX_DATABASE_NAME_SIZE 128 #define NDB_MAX_SCHEMA_NAME_SIZE 128 #define NDB_MAX_TAB_NAME_SIZE 128 +#define NDB_MAX_ATTR_NAME_SIZE 32 #define NDB_MAX_ATTRIBUTES_IN_TABLE 128 #define NDB_MAX_TUPLE_SIZE_IN_WORDS 2013 diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 044cb85b913..838cf69855a 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -1393,8 +1393,13 @@ int ha_ndbcluster::set_bounds(NdbIndexScanOperation *op, // Set bound if not cancelled via type -1 if (p.bound_type != -1) - if (op->setBound(field->field_name, p.bound_type, p.bound_ptr)) + { + char truncated_field_name[NDB_MAX_ATTR_NAME_SIZE]; + strnmov(truncated_field_name,field->field_name,sizeof(truncated_field_name)); + truncated_field_name[sizeof(truncated_field_name)-1]= '\0'; + if (op->setBound(truncated_field_name, p.bound_type, p.bound_ptr)) ERR_RETURN(op->getNdbError()); + } } } @@ -3102,7 +3107,12 @@ static int create_ndb_column(NDBCOL &col, HA_CREATE_INFO *info) { // Set name - col.setName(field->field_name); + { + char truncated_field_name[NDB_MAX_ATTR_NAME_SIZE]; + strnmov(truncated_field_name,field->field_name,sizeof(truncated_field_name)); + truncated_field_name[sizeof(truncated_field_name)-1]= '\0'; + col.setName(truncated_field_name); + } // Get char set CHARSET_INFO *cs= field->charset(); // Set type and sizes @@ -3430,7 +3440,12 @@ int ha_ndbcluster::create_index(const char *name, { Field *field= key_part->field; DBUG_PRINT("info", ("attr: %s", field->field_name)); - ndb_index.addColumnName(field->field_name); + { + char truncated_field_name[NDB_MAX_ATTR_NAME_SIZE]; + strnmov(truncated_field_name,field->field_name,sizeof(truncated_field_name)); + truncated_field_name[sizeof(truncated_field_name)-1]= '\0'; + ndb_index.addColumnName(truncated_field_name); + } } if (dict->createIndex(ndb_index))