Commit 1aa81f38 authored by unknown's avatar unknown
Browse files

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
parent e3ac81be
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -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;
+1 −0
Original line number Diff line number Diff line
@@ -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
+18 −3
Original line number Diff line number Diff line
@@ -1393,10 +1393,15 @@ 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());
	}
      }
    }

    tot_len+= part_store_len;
  }
@@ -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))