mirror of
				https://github.com/MariaDB/server.git
				synced 2025-11-03 14:33:32 +03:00 
			
		
		
		
	Add indexes to test toolkit
This commit is contained in:
		@@ -50,13 +50,12 @@ public:
 | 
				
			|||||||
  
 | 
					  
 | 
				
			||||||
  NDBT_Table(const char* name, 
 | 
					  NDBT_Table(const char* name, 
 | 
				
			||||||
	     int noOfAttributes,
 | 
						     int noOfAttributes,
 | 
				
			||||||
	     const NdbDictionary::Column attributes[],
 | 
						     const NdbDictionary::Column attributes[])
 | 
				
			||||||
	     bool stored = true)
 | 
					 | 
				
			||||||
    : NdbDictionary::Table(name)
 | 
					    : NdbDictionary::Table(name)
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    assert(name != 0);
 | 
					    assert(name != 0);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    setStoredTable(stored);
 | 
					    //setStoredTable(stored);
 | 
				
			||||||
    for(int i = 0; i<noOfAttributes; i++)
 | 
					    for(int i = 0; i<noOfAttributes; i++)
 | 
				
			||||||
      addColumn(attributes[i]);
 | 
					      addColumn(attributes[i]);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,7 +26,8 @@
 | 
				
			|||||||
class NDBT_Tables {
 | 
					class NDBT_Tables {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  static int createTable(Ndb* pNdb, const char* _name, bool _temp = false);
 | 
					  static int createTable(Ndb* pNdb, const char* _name, bool _temp = false, 
 | 
				
			||||||
 | 
								 bool existsOK = false);
 | 
				
			||||||
  static int createAllTables(Ndb* pNdb, bool _temp, bool existsOK = false);
 | 
					  static int createAllTables(Ndb* pNdb, bool _temp, bool existsOK = false);
 | 
				
			||||||
  static int createAllTables(Ndb* pNdb);
 | 
					  static int createAllTables(Ndb* pNdb);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -297,7 +297,7 @@ NDBT_Table T14("T14", sizeof(T14Attribs)/sizeof(NDBT_Attribute), T14Attribs);
 | 
				
			|||||||
*/
 | 
					*/
 | 
				
			||||||
static 
 | 
					static 
 | 
				
			||||||
const
 | 
					const
 | 
				
			||||||
NDBT_Attribute C2_PORTS_Attribs[] = {
 | 
					NDBT_Attribute I1_Cols[] = {
 | 
				
			||||||
  NDBT_Attribute("ID", NdbDictionary::Column::Unsigned, true),
 | 
					  NDBT_Attribute("ID", NdbDictionary::Column::Unsigned, true),
 | 
				
			||||||
  NDBT_Attribute("PORT", NdbDictionary::Column::Char, 16, true),
 | 
					  NDBT_Attribute("PORT", NdbDictionary::Column::Char, 16, true),
 | 
				
			||||||
  NDBT_Attribute("ACCESSNODE", NdbDictionary::Column::Char, 16, true),
 | 
					  NDBT_Attribute("ACCESSNODE", NdbDictionary::Column::Char, 16, true),
 | 
				
			||||||
@@ -310,11 +310,19 @@ NDBT_Attribute C2_PORTS_Attribs[] = {
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static
 | 
					static
 | 
				
			||||||
NDBT_Table C2_PORTS("C2_PORTS", sizeof(C2_PORTS_Attribs)/sizeof(NDBT_Attribute), C2_PORTS_Attribs);
 | 
					const
 | 
				
			||||||
 | 
					char* I1_Indexes[] = {
 | 
				
			||||||
 | 
					  "UNIQUE", "ID", "PORT", "ACCESSNODE", "POP", "PORTSTATE", 0,
 | 
				
			||||||
 | 
					  0
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static
 | 
				
			||||||
 | 
					NDBT_Table I1("I1", sizeof(I1_Cols)/sizeof(NDBT_Attribute), I1_Cols
 | 
				
			||||||
 | 
						      );// ,I1_Indexes);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static 
 | 
					static 
 | 
				
			||||||
const
 | 
					const
 | 
				
			||||||
NDBT_Attribute C2_SERVICES_Attribs[] = {
 | 
					NDBT_Attribute I2_Cols[] = {
 | 
				
			||||||
  NDBT_Attribute("ID", NdbDictionary::Column::Unsigned, true),
 | 
					  NDBT_Attribute("ID", NdbDictionary::Column::Unsigned, true),
 | 
				
			||||||
  NDBT_Attribute("PORT", NdbDictionary::Column::Char, 16, true),
 | 
					  NDBT_Attribute("PORT", NdbDictionary::Column::Char, 16, true),
 | 
				
			||||||
  NDBT_Attribute("ACCESSNODE", NdbDictionary::Column::Char, 16, true),
 | 
					  NDBT_Attribute("ACCESSNODE", NdbDictionary::Column::Char, 16, true),
 | 
				
			||||||
@@ -331,12 +339,20 @@ NDBT_Attribute C2_SERVICES_Attribs[] = {
 | 
				
			|||||||
  NDBT_Attribute("UPDATES", NdbDictionary::Column::Unsigned)
 | 
					  NDBT_Attribute("UPDATES", NdbDictionary::Column::Unsigned)
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const
 | 
				
			||||||
 | 
					char* I2_Indexes[] = {
 | 
				
			||||||
 | 
					  "ORDERED", "CUSTOMER_ID", 0,
 | 
				
			||||||
 | 
					  "ORDERED", "NUM_IP", 0,
 | 
				
			||||||
 | 
					  0
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static
 | 
					static
 | 
				
			||||||
NDBT_Table C2_SERVICES("C2_SERVICES", sizeof(C2_SERVICES_Attribs)/sizeof(NDBT_Attribute), C2_SERVICES_Attribs);
 | 
					NDBT_Table I2("I2", sizeof(I2_Cols)/sizeof(NDBT_Attribute), I2_Cols
 | 
				
			||||||
 | 
						      );//, I2_Indexes);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static 
 | 
					static 
 | 
				
			||||||
const
 | 
					const
 | 
				
			||||||
NDBT_Attribute C2_CLIENTS_Attribs[] = {
 | 
					NDBT_Attribute I3_Cols[] = {
 | 
				
			||||||
  NDBT_Attribute("ID", NdbDictionary::Column::Unsigned, true),
 | 
					  NDBT_Attribute("ID", NdbDictionary::Column::Unsigned, true),
 | 
				
			||||||
  NDBT_Attribute("PORT", NdbDictionary::Column::Char, 16), // SI2
 | 
					  NDBT_Attribute("PORT", NdbDictionary::Column::Char, 16), // SI2
 | 
				
			||||||
  NDBT_Attribute("ACCESSNODE", NdbDictionary::Column::Char, 16), // SI2
 | 
					  NDBT_Attribute("ACCESSNODE", NdbDictionary::Column::Char, 16), // SI2
 | 
				
			||||||
@@ -355,8 +371,17 @@ NDBT_Attribute C2_CLIENTS_Attribs[] = {
 | 
				
			|||||||
  NDBT_Attribute("UPDATES", NdbDictionary::Column::Unsigned)
 | 
					  NDBT_Attribute("UPDATES", NdbDictionary::Column::Unsigned)
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const
 | 
				
			||||||
 | 
					char* I3_Indexes[] = {
 | 
				
			||||||
 | 
					  "UNIQUE", "ID", 0,
 | 
				
			||||||
 | 
					  "ORDERED", "MAC", 0,
 | 
				
			||||||
 | 
					  "ORDERED", "GW", 0,
 | 
				
			||||||
 | 
					  0
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static
 | 
					static
 | 
				
			||||||
NDBT_Table C2_CLIENTS("C2_CLIENTS", sizeof(C2_CLIENTS_Attribs)/sizeof(NDBT_Attribute), C2_CLIENTS_Attribs);
 | 
					NDBT_Table I3("I3", sizeof(I3_Cols)/sizeof(NDBT_Attribute), I3_Cols
 | 
				
			||||||
 | 
						      ); // ,I3_Indexes);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Define array with pointer to all tables 
 | 
					// Define array with pointer to all tables 
 | 
				
			||||||
static
 | 
					static
 | 
				
			||||||
@@ -377,10 +402,23 @@ NDBT_Table *test_tables[]=
 | 
				
			|||||||
  &T12,
 | 
					  &T12,
 | 
				
			||||||
  &T13,
 | 
					  &T13,
 | 
				
			||||||
  &T14,
 | 
					  &T14,
 | 
				
			||||||
  &C2_PORTS,
 | 
					  &I1,
 | 
				
			||||||
  &C2_SERVICES,
 | 
					  &I2,
 | 
				
			||||||
  &C2_CLIENTS
 | 
					  &I3
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct NDBT_IndexList {
 | 
				
			||||||
 | 
					  const char * m_table;
 | 
				
			||||||
 | 
					  const char ** m_indexes;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static
 | 
				
			||||||
 | 
					const
 | 
				
			||||||
 | 
					NDBT_IndexList indexes[] = {
 | 
				
			||||||
 | 
					  "I1", I1_Indexes, 
 | 
				
			||||||
 | 
					  "I2", I2_Indexes, 
 | 
				
			||||||
 | 
					  "I3", I3_Indexes,
 | 
				
			||||||
 | 
					  0, 0
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static
 | 
					static
 | 
				
			||||||
@@ -765,25 +803,10 @@ int
 | 
				
			|||||||
NDBT_Tables::createAllTables(Ndb* pNdb, bool _temp, bool existsOk){
 | 
					NDBT_Tables::createAllTables(Ndb* pNdb, bool _temp, bool existsOk){
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  for (int i=0; i < NDBT_Tables::getNumTables(); i++){
 | 
					  for (int i=0; i < NDBT_Tables::getNumTables(); i++){
 | 
				
			||||||
 | 
					    int ret= createTable(pNdb, 
 | 
				
			||||||
    const NdbDictionary::Table* tab = NDBT_Tables::getTable(i);
 | 
								 NDBT_Tables::getTable(i)->getName(), _temp, existsOk);
 | 
				
			||||||
    if (tab == NULL){
 | 
					    if(ret)
 | 
				
			||||||
      return NDBT_ProgramExit(NDBT_FAILED);
 | 
					      return ret;
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    // Set temporary table 
 | 
					 | 
				
			||||||
    NdbDictionary::Table tmpTab(* tab);
 | 
					 | 
				
			||||||
    tmpTab.setStoredTable(_temp? 0 : 1);
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    int r = pNdb->getDictionary()->createTable(tmpTab);
 | 
					 | 
				
			||||||
    int err = pNdb->getDictionary()->getNdbError().code;
 | 
					 | 
				
			||||||
    if(r == -1){
 | 
					 | 
				
			||||||
      if (existsOk && err == 721)
 | 
					 | 
				
			||||||
	;
 | 
					 | 
				
			||||||
      else {
 | 
					 | 
				
			||||||
	return NDBT_FAILED;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  return NDBT_OK;
 | 
					  return NDBT_OK;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -794,7 +817,8 @@ NDBT_Tables::createAllTables(Ndb* pNdb){
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int
 | 
					int
 | 
				
			||||||
NDBT_Tables::createTable(Ndb* pNdb, const char* _name, bool _temp){
 | 
					NDBT_Tables::createTable(Ndb* pNdb, const char* _name, bool _temp, 
 | 
				
			||||||
 | 
								 bool existsOk){
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  const NdbDictionary::Table* tab = NDBT_Tables::getTable(_name);
 | 
					  const NdbDictionary::Table* tab = NDBT_Tables::getTable(_name);
 | 
				
			||||||
  if (tab == NULL){
 | 
					  if (tab == NULL){
 | 
				
			||||||
@@ -804,10 +828,59 @@ NDBT_Tables::createTable(Ndb* pNdb, const char* _name, bool _temp){
 | 
				
			|||||||
    return NDBT_WRONGARGS;
 | 
					    return NDBT_WRONGARGS;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  int r = 0;
 | 
				
			||||||
 | 
					  do {
 | 
				
			||||||
    NdbDictionary::Table tmpTab(* tab);
 | 
					    NdbDictionary::Table tmpTab(* tab);
 | 
				
			||||||
    tmpTab.setStoredTable(_temp ? 0 : 1);
 | 
					    tmpTab.setStoredTable(_temp ? 0 : 1);
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  int r = pNdb->getDictionary()->createTable(tmpTab);
 | 
					    r = pNdb->getDictionary()->createTable(tmpTab);
 | 
				
			||||||
 | 
					    if(r == -1){
 | 
				
			||||||
 | 
					      if(!existsOk)
 | 
				
			||||||
 | 
						break;
 | 
				
			||||||
 | 
					      if(pNdb->getDictionary()->getNdbError().code != 721){
 | 
				
			||||||
 | 
						ndbout << pNdb->getDictionary()->getNdbError() << endl;
 | 
				
			||||||
 | 
						break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      r = 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Uint32 i = 0;
 | 
				
			||||||
 | 
					    for(Uint32 i = 0; indexes[i].m_table != 0; i++){
 | 
				
			||||||
 | 
					      if(strcmp(indexes[i].m_table, _name) != 0)
 | 
				
			||||||
 | 
						continue;
 | 
				
			||||||
 | 
					      Uint32 j = 0;
 | 
				
			||||||
 | 
					      while(indexes[i].m_indexes[j] != 0){
 | 
				
			||||||
 | 
						NdbDictionary::Index tmpIndx;
 | 
				
			||||||
 | 
						BaseString name;
 | 
				
			||||||
 | 
						name.assfmt("%s$NDBT_IDX%d", _name, j);
 | 
				
			||||||
 | 
						tmpIndx.setName(name.c_str());
 | 
				
			||||||
 | 
						tmpIndx.setTable(_name);
 | 
				
			||||||
 | 
						bool logging = !_temp;
 | 
				
			||||||
 | 
						if(strcmp(indexes[i].m_indexes[j], "ORDERED") == 0){
 | 
				
			||||||
 | 
						  logging = false;
 | 
				
			||||||
 | 
						  tmpIndx.setType(NdbDictionary::Index::OrderedIndex);
 | 
				
			||||||
 | 
						} else if(strcmp(indexes[i].m_indexes[j], "UNIQUE") == 0){
 | 
				
			||||||
 | 
						  tmpIndx.setType(NdbDictionary::Index::UniqueHashIndex);
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
						  ndbout << "Unknown index type";
 | 
				
			||||||
 | 
						  abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						tmpIndx.setLogging(logging);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						j++;
 | 
				
			||||||
 | 
						while(indexes[i].m_indexes[j] != 0){
 | 
				
			||||||
 | 
						  tmpIndx.addIndexColumn(indexes[i].m_indexes[j]);
 | 
				
			||||||
 | 
						  j++;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						j++;
 | 
				
			||||||
 | 
						if(pNdb->getDictionary()->createIndex(tmpIndx) != 0){
 | 
				
			||||||
 | 
						  ndbout << pNdb->getDictionary()->getNdbError() << endl;
 | 
				
			||||||
 | 
						  return NDBT_FAILED;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  } while(false);
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
  return r;
 | 
					  return r;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -828,7 +828,7 @@ void NDBT_TestSuite::execute(Ndb* ndb, const NdbDictionary::Table* pTab,
 | 
				
			|||||||
	continue;
 | 
						continue;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      if(pDict->createTable(* pTab) != 0){
 | 
					      if(NDBT_Tables::createTable(ndb, pTab->getName()) != 0){
 | 
				
			||||||
	numTestsFail++;
 | 
						numTestsFail++;
 | 
				
			||||||
	numTestsExecuted++;
 | 
						numTestsExecuted++;
 | 
				
			||||||
	g_err << "ERROR1: Failed to create table " << pTab->getName()
 | 
						g_err << "ERROR1: Failed to create table " << pTab->getName()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user