NdbDictionaryImpl.hpp 16.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/* Copyright (C) 2003 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#ifndef NdbDictionaryImpl_H
#define NdbDictionaryImpl_H

#include <ndb_types.h>
#include <kernel_types.h>
#include <NdbError.hpp>
#include <BaseString.hpp>
#include <Vector.hpp>
#include <UtilBuffer.hpp>
#include <NdbDictionary.hpp>
#include <Bitmask.hpp>
#include <AttributeList.hpp>
#include <Ndb.hpp>
30
#include "NdbWaiter.hpp"
31 32 33 34
#include "DictCache.hpp"

class NdbDictObjectImpl {
public:
35
  Uint32 m_version;
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
  NdbDictionary::Object::Status m_status;
  
  bool change();
protected:
  NdbDictObjectImpl() :
    m_status(NdbDictionary::Object::New) {
  }
};

/**
 * Column
 */
class NdbColumnImpl : public NdbDictionary::Column {
public:
  NdbColumnImpl();
  NdbColumnImpl(NdbDictionary::Column &); // This is not a copy constructor
  ~NdbColumnImpl();
  NdbColumnImpl& operator=(const NdbColumnImpl&);
54
  void init(Type t = Unsigned);
55 56 57 58 59 60 61
  
  int m_attrId;
  BaseString m_name;
  NdbDictionary::Column::Type m_type;
  int m_precision;
  int m_scale;
  int m_length;
pekka@mysql.com's avatar
pekka@mysql.com committed
62
  CHARSET_INFO * m_cs;          // not const in MySQL
63 64 65 66 67 68 69
  
  bool m_pk;
  bool m_distributionKey;
  bool m_nullable;
  bool m_autoIncrement;
  Uint64 m_autoIncrementInitialValue;
  BaseString m_defaultValue;
mskold@mysql.com's avatar
mskold@mysql.com committed
70
  NdbTableImpl * m_blobTable;
71 72 73 74 75 76 77

  /**
   * Internal types and sizes, and aggregates
   */
  Uint32 m_attrSize;            // element size (size when arraySize==1)
  Uint32 m_arraySize;           // length or length+2 for Var* types
  Uint32 m_keyInfoPos;
78
  // TODO: use bits in attr desc 2
79
  bool getInterpretableType() const ;
pekka@mysql.com's avatar
pekka@mysql.com committed
80
  bool getCharType() const;
81
  bool getStringType() const;
pekka@mysql.com's avatar
pekka@mysql.com committed
82
  bool getBlobType() const;
83 84 85 86 87 88 89 90 91

  /**
   * Equality/assign
   */
  bool equal(const NdbColumnImpl&) const;

  static NdbColumnImpl & getImpl(NdbDictionary::Column & t);
  static const NdbColumnImpl & getImpl(const NdbDictionary::Column & t);
  NdbDictionary::Column * m_facade;
joreland@mysql.com's avatar
joreland@mysql.com committed
92 93

  static NdbDictionary::Column * create_psuedo(const char *);
94 95 96 97

  // Get total length in bytes, used by NdbOperation
  // backported from 5.1
  bool get_var_length(const void* value, Uint32& len) const;
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
};

class NdbTableImpl : public NdbDictionary::Table, public NdbDictObjectImpl {
public:
  NdbTableImpl();
  NdbTableImpl(NdbDictionary::Table &);
  ~NdbTableImpl();
  
  void init();
  void setName(const char * name);
  const char * getName() const;

  Uint32 m_changeMask;
  Uint32 m_tableId;
  BaseString m_internalName;
  BaseString m_externalName;
  BaseString m_newExternalName; // Used for alter table
  UtilBuffer m_frm; 
  NdbDictionary::Object::FragmentType m_fragmentType;

  /**
   * 
   */
  Uint32 m_columnHashMask;
  Vector<Uint32> m_columnHash;
  Vector<NdbColumnImpl *> m_columns;
  void buildColumnHash(); 
125 126 127 128 129 130 131 132

  /**
   * Fragment info
   */
  Uint32 m_hashValueMask;
  Uint32 m_hashpointerValue;
  Vector<Uint16> m_fragments;

133 134 135
  Uint64 m_max_rows;
  Uint64 m_min_rows;

136 137 138 139
  bool m_logging;
  int m_kvalue;
  int m_minLoadFactor;
  int m_maxLoadFactor;
140 141
  Uint16 m_keyLenInWords;
  Uint16 m_fragmentCount;
joreland@mysql.com's avatar
joreland@mysql.com committed
142

143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
  NdbDictionaryImpl * m_dictionary;
  NdbIndexImpl * m_index;
  NdbColumnImpl * getColumn(unsigned attrId);
  NdbColumnImpl * getColumn(const char * name);
  const NdbColumnImpl * getColumn(unsigned attrId) const;
  const NdbColumnImpl * getColumn(const char * name) const;
  
  /**
   * Index only stuff
   */
  BaseString m_primaryTable;
  NdbDictionary::Index::Type m_indexType;

  /**
   * Aggregates
   */
159 160 161
  Uint8 m_noOfKeys;
  Uint8 m_noOfDistributionKeys;
  Uint8 m_noOfBlobs;
162 163
  
  Uint8 m_replicaCount;
164 165 166 167 168 169 170 171 172 173

  /**
   * Equality/assign
   */
  bool equal(const NdbTableImpl&) const;
  void assign(const NdbTableImpl&);

  static NdbTableImpl & getImpl(NdbDictionary::Table & t);
  static NdbTableImpl & getImpl(const NdbDictionary::Table & t);
  NdbDictionary::Table * m_facade;
174 175 176 177 178
  
  /**
   * Return count
   */
  Uint32 get_nodes(Uint32 hashValue, const Uint16** nodes) const ;
179 180 181 182 183 184 185 186
};

class NdbIndexImpl : public NdbDictionary::Index, public NdbDictObjectImpl {
public:
  NdbIndexImpl();
  NdbIndexImpl(NdbDictionary::Index &);
  ~NdbIndexImpl();

msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
187
  void init();
188 189 190 191
  void setName(const char * name);
  const char * getName() const;
  void setTable(const char * table);
  const char * getTable() const;
192
  const NdbTableImpl * getIndexTable() const;
193 194 195 196 197 198

  Uint32 m_indexId;
  BaseString m_internalName;
  BaseString m_externalName;
  BaseString m_tableName;
  Vector<NdbColumnImpl *> m_columns;
199
  Vector<int> m_key_ids;
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
  NdbDictionary::Index::Type m_type;

  bool m_logging;
  
  NdbTableImpl * m_table;
  
  static NdbIndexImpl & getImpl(NdbDictionary::Index & t);
  static NdbIndexImpl & getImpl(const NdbDictionary::Index & t);
  NdbDictionary::Index * m_facade;
};

class NdbDictInterface {
public:
  NdbDictInterface(NdbError& err) : m_error(err) {
    m_reference = 0;
    m_masterNodeId = 0;
    m_transporter= NULL;
  }
  ~NdbDictInterface();
  
  bool setTransporter(class Ndb * ndb, class TransporterFacade * tf);
  bool setTransporter(class TransporterFacade * tf);
  
  // To abstract the stuff thats made in all create/drop/lists below
  int
  dictSignal(NdbApiSignal* signal, 
	     LinearSectionPtr ptr[3], int noLPTR,
	     const int useMasterNodeId,
	     const Uint32 RETRIES,
	     const WaitSignalType wst,
	     const int theWait,
	     const int *errcodes,
	     const int noerrcodes,
	     const int temporaryMask = 0);

  int createOrAlterTable(class Ndb & ndb, NdbTableImpl &, bool alter);

  int createTable(class Ndb & ndb, NdbTableImpl &);
  int createTable(NdbApiSignal* signal, LinearSectionPtr ptr[3]);

  int alterTable(class Ndb & ndb, NdbTableImpl &);
  int alterTable(NdbApiSignal* signal, LinearSectionPtr ptr[3]);

  int createIndex(class Ndb & ndb,
		  NdbIndexImpl &, 
		  const NdbTableImpl &);
  int createIndex(NdbApiSignal* signal, LinearSectionPtr ptr[3]);
  
  int dropTable(const NdbTableImpl &);
  int dropTable(NdbApiSignal* signal, LinearSectionPtr ptr[3]);

  int dropIndex(const NdbIndexImpl &, const NdbTableImpl &);
  int dropIndex(NdbApiSignal* signal, LinearSectionPtr ptr[3]);

254
  int listObjects(NdbDictionary::Dictionary::List& list, Uint32 requestData, bool fullyQualifiedNames);
255 256
  int listObjects(NdbApiSignal* signal);
  
257 258
/*  NdbTableImpl * getTable(int tableId, bool fullyQualifiedNames); */
  NdbTableImpl * getTable(const BaseString& name, bool fullyQualifiedNames);
259 260
  NdbTableImpl * getTable(class NdbApiSignal * signal, 
			  LinearSectionPtr ptr[3],
261
			  Uint32 noOfSections, bool fullyQualifiedNames);
262 263

  static int parseTableInfo(NdbTableImpl ** dst, 
264 265
			    const Uint32 * data, Uint32 len,
			    bool fullyQualifiedNames);
266
  
267
  static int create_index_obj_from_table(NdbIndexImpl ** dst, 
268 269
					 NdbTableImpl* index_table,
					 const NdbTableImpl* primary_table);
270
  
271 272 273 274 275 276 277 278 279 280 281
  NdbError & m_error;
private:
  Uint32 m_reference;
  Uint32 m_masterNodeId;
  
  NdbWaiter m_waiter;
  class TransporterFacade * m_transporter;
  
  friend class Ndb;
  static void execSignal(void* dictImpl, 
			 class NdbApiSignal* signal, 
joreland@mysql.com's avatar
joreland@mysql.com committed
282
			 struct LinearSectionPtr ptr[3]);
283
  
284
  static void execNodeStatus(void* dictImpl, Uint32, 
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
			     bool alive, bool nfCompleted);  
  
  void execGET_TABINFO_REF(NdbApiSignal *, LinearSectionPtr ptr[3]);
  void execGET_TABINFO_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);
  void execCREATE_TABLE_REF(NdbApiSignal *, LinearSectionPtr ptr[3]);
  void execCREATE_TABLE_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);
  void execALTER_TABLE_REF(NdbApiSignal *, LinearSectionPtr ptr[3]);
  void execALTER_TABLE_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);

  void execCREATE_INDX_REF(NdbApiSignal *, LinearSectionPtr ptr[3]);
  void execCREATE_INDX_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);
  void execDROP_INDX_REF(NdbApiSignal *, LinearSectionPtr ptr[3]);
  void execDROP_INDX_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);

  void execDROP_TABLE_REF(NdbApiSignal *, LinearSectionPtr ptr[3]);
  void execDROP_TABLE_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);
  void execLIST_TABLES_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);

  Uint32 m_fragmentId;
  UtilBuffer m_buffer;
};

class NdbDictionaryImpl : public NdbDictionary::Dictionary {
public:
  NdbDictionaryImpl(Ndb &ndb);
  NdbDictionaryImpl(Ndb &ndb, NdbDictionary::Dictionary & f);
  ~NdbDictionaryImpl();

  bool setTransporter(class Ndb * ndb, class TransporterFacade * tf);
  bool setTransporter(class TransporterFacade * tf);
msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
315

pekka@mysql.com's avatar
pekka@mysql.com committed
316 317
  int createTable(NdbTableImpl &t);
  int createBlobTables(NdbTableImpl &);
mskold@mysql.com's avatar
mskold@mysql.com committed
318
  int addBlobTables(NdbTableImpl &);
319 320 321
  int alterTable(NdbTableImpl &t);
  int dropTable(const char * name);
  int dropTable(NdbTableImpl &);
pekka@mysql.com's avatar
pekka@mysql.com committed
322
  int dropBlobTables(NdbTableImpl &);
323 324 325 326 327 328
  int invalidateObject(NdbTableImpl &);
  int removeCachedObject(NdbTableImpl &);

  int createIndex(NdbIndexImpl &ix);
  int dropIndex(const char * indexName, 
		const char * tableName);
329
  int dropIndex(NdbIndexImpl &);
330 331 332 333
  NdbTableImpl * getIndexTable(NdbIndexImpl * index, 
			       NdbTableImpl * table);

  int listObjects(List& list, NdbDictionary::Object::Type type);
joreland@mysql.com's avatar
joreland@mysql.com committed
334
  int listIndexes(List& list, Uint32 indexId);
335

336
  NdbTableImpl * getTable(const char * tableName, void **data= 0);
337 338
  Ndb_local_table_info* get_local_table_info(
    const BaseString& internalTableName, bool do_add_blob_tables);
339 340
  NdbIndexImpl * getIndex(const char * indexName,
			  const char * tableName);
341 342
  NdbIndexImpl * getIndex(const char * indexName,
			  NdbTableImpl * table);
343 344 345
  
  const NdbError & getNdbError() const;
  NdbError m_error;
346
  Uint32 m_local_table_data_size;
347 348 349 350 351 352 353 354 355 356

  LocalDictCache m_localHash;
  GlobalDictCache * m_globalHash;

  static NdbDictionaryImpl & getImpl(NdbDictionary::Dictionary & t);
  static const NdbDictionaryImpl & getImpl(const NdbDictionary::Dictionary &t);
  NdbDictionary::Dictionary * m_facade;

  NdbDictInterface m_receiver;
  Ndb & m_ndb;
357
private:
358 359 360
  NdbIndexImpl * getIndexImpl(const char * name,
                              const BaseString& internalName);
  Ndb_local_table_info * fetchGlobalTableImpl(const BaseString& internalName);
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
};

inline
NdbColumnImpl &
NdbColumnImpl::getImpl(NdbDictionary::Column & t){
  return t.m_impl;
}

inline
const NdbColumnImpl &
NdbColumnImpl::getImpl(const NdbDictionary::Column & t){
  return t.m_impl;
}

inline
bool 
NdbColumnImpl::getInterpretableType() const {
  return (m_type == NdbDictionary::Column::Unsigned ||
	  m_type == NdbDictionary::Column::Bigunsigned);
}

pekka@mysql.com's avatar
pekka@mysql.com committed
382 383 384 385 386
inline
bool 
NdbColumnImpl::getCharType() const {
  return (m_type == NdbDictionary::Column::Char ||
          m_type == NdbDictionary::Column::Varchar ||
pekka@mysql.com's avatar
pekka@mysql.com committed
387 388
          m_type == NdbDictionary::Column::Text ||
          m_type == NdbDictionary::Column::Longvarchar);
pekka@mysql.com's avatar
pekka@mysql.com committed
389
}
390 391 392 393 394 395 396 397 398 399 400

inline
bool 
NdbColumnImpl::getStringType() const {
  return (m_type == NdbDictionary::Column::Char ||
          m_type == NdbDictionary::Column::Varchar ||
          m_type == NdbDictionary::Column::Longvarchar ||
          m_type == NdbDictionary::Column::Binary ||
          m_type == NdbDictionary::Column::Varbinary ||
          m_type == NdbDictionary::Column::Longvarbinary);
}
pekka@mysql.com's avatar
pekka@mysql.com committed
401
   
pekka@mysql.com's avatar
pekka@mysql.com committed
402 403 404 405
inline
bool 
NdbColumnImpl::getBlobType() const {
  return (m_type == NdbDictionary::Column::Blob ||
pekka@mysql.com's avatar
pekka@mysql.com committed
406
	  m_type == NdbDictionary::Column::Text);
pekka@mysql.com's avatar
pekka@mysql.com committed
407 408
}

409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
inline
bool
NdbColumnImpl::get_var_length(const void* value, Uint32& len) const
{
  Uint32 max_len = m_attrSize * m_arraySize;
  switch (m_type) {
  case NdbDictionary::Column::Varchar:
  case NdbDictionary::Column::Varbinary:
    len = 1 + *((Uint8*)value);
    break;
  case NdbDictionary::Column::Longvarchar:
  case NdbDictionary::Column::Longvarbinary:
    len = 2 + uint2korr((char*)value);
    break;
  default:
    len = max_len;
    return true;
  }
  return (len <= max_len);
}

430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
inline
NdbTableImpl &
NdbTableImpl::getImpl(NdbDictionary::Table & t){
  return t.m_impl;
}

inline
NdbTableImpl &
NdbTableImpl::getImpl(const NdbDictionary::Table & t){
  return t.m_impl;
}

inline
NdbColumnImpl *
NdbTableImpl::getColumn(unsigned attrId){
  if(m_columns.size() > attrId){
    return m_columns[attrId];
  }
  return 0;
}

inline
Uint32
Hash( const char* str ){
  Uint32 h = 0;
  Uint32 len = strlen(str);
  while(len >= 4){
    h = (h << 5) + h + str[0];
    h = (h << 5) + h + str[1];
    h = (h << 5) + h + str[2];
    h = (h << 5) + h + str[3];
    len -= 4;
    str += 4;
  }
  
  switch(len){
  case 3:
    h = (h << 5) + h + *str++;
  case 2:
    h = (h << 5) + h + *str++;
  case 1:
    h = (h << 5) + h + *str++;
  }
  return h + h;
}


inline
NdbColumnImpl *
NdbTableImpl::getColumn(const char * name){

  Uint32 sz = m_columns.size();
  NdbColumnImpl** cols = m_columns.getBase();
  const Uint32 * hashtable = m_columnHash.getBase();

  if(sz > 5 && false){
    Uint32 hashValue = Hash(name) & 0xFFFE;
    Uint32 bucket = hashValue & m_columnHashMask;
    bucket = (bucket < sz ? bucket : bucket - sz);
    hashtable += bucket;
    Uint32 tmp = * hashtable;
    if((tmp & 1) == 1 ){ // No chaining
      sz = 1;
    } else {
      sz = (tmp >> 16);
      hashtable += (tmp & 0xFFFE) >> 1;
      tmp = * hashtable;
    }
    do {
      if(hashValue == (tmp & 0xFFFE)){
	NdbColumnImpl* col = cols[tmp >> 16];
msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
501
	if(strncmp(name, col->m_name.c_str(), col->m_name.length()) == 0){
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
	  return col;
	}
      }
      hashtable++;
      tmp = * hashtable;
    } while(--sz > 0);
#if 0
    Uint32 dir = m_columnHash[bucket];
    Uint32 pos = bucket + ((dir & 0xFFFE) >> 1); 
    Uint32 cnt = dir >> 16;
    ndbout_c("col: %s hv: %x bucket: %d dir: %x pos: %d cnt: %d tmp: %d -> 0", 
	     name, hashValue, bucket, dir, pos, cnt, tmp);
#endif
    return 0;
  } else {
    for(Uint32 i = 0; i<sz; i++){
      NdbColumnImpl* col = * cols++;
msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
519
      if(col != 0 && strcmp(name, col->m_name.c_str()) == 0)
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
	return col;
    }
  }
  return 0;
}

inline
const NdbColumnImpl *
NdbTableImpl::getColumn(unsigned attrId) const {
  if(m_columns.size() > attrId){
    return m_columns[attrId];
  }
  return 0;
}

inline
const NdbColumnImpl *
NdbTableImpl::getColumn(const char * name) const {
  Uint32 sz = m_columns.size();
  NdbColumnImpl* const * cols = m_columns.getBase();
  for(Uint32 i = 0; i<sz; i++, cols++){
    NdbColumnImpl* col = * cols;
    if(col != 0 && strcmp(name, col->m_name.c_str()) == 0)
      return col;
  }
  return 0;
}

inline
NdbIndexImpl &
NdbIndexImpl::getImpl(NdbDictionary::Index & t){
  return t.m_impl;
}

inline
NdbIndexImpl &
NdbIndexImpl::getImpl(const NdbDictionary::Index & t){
  return t.m_impl;
}

inline
NdbDictionaryImpl &
NdbDictionaryImpl::getImpl(NdbDictionary::Dictionary & t){
  return t.m_impl;
}

inline
const NdbDictionaryImpl &
NdbDictionaryImpl::getImpl(const NdbDictionary::Dictionary & t){
  return t.m_impl;
}

/*****************************************************************
 * Inline:d getters
 */

inline
577 578
NdbTableImpl *
NdbDictionaryImpl::getTable(const char * table_name, void **data)
579
{
580
  const BaseString internal_tabname(m_ndb.internalize_table_name(table_name));
581
  Ndb_local_table_info *info=
582 583
    get_local_table_info(internal_tabname, true);
  if (info == 0)
584
    return 0;
585 586

  if (data)
587
    *data= info->m_local_data;
588

589
  return info->m_table_impl;
590 591 592
}

inline
593
Ndb_local_table_info * 
594
NdbDictionaryImpl::get_local_table_info(const BaseString& internalTableName,
595
					bool do_add_blob_tables)
596
{
597
  Ndb_local_table_info *info= m_localHash.get(internalTableName.c_str());
598 599 600 601 602 603
  if (info == 0) {
    info= fetchGlobalTableImpl(internalTableName);
    if (info == 0) {
      return 0;
    }
  }
joreland@mysql.com's avatar
joreland@mysql.com committed
604 605 606
  if (do_add_blob_tables && info->m_table_impl->m_noOfBlobs)
    addBlobTables(*(info->m_table_impl));
  
607
  return info; // autoincrement already initialized
608 609
}

610

611 612
inline
NdbIndexImpl * 
613 614
NdbDictionaryImpl::getIndex(const char * index_name,
			    const char * table_name)
615
{
616
  return getIndex(index_name, (table_name) ? getTable(table_name) : NULL);
617 618 619 620
}

inline
NdbIndexImpl * 
621
NdbDictionaryImpl::getIndex(const char * index_name,
622
			    NdbTableImpl * table)
623
{
624
  if (table || m_ndb.usingFullyQualifiedNames())
625 626
  {
    const BaseString internal_indexname(
627
      (table)
628
      ?
629
      m_ndb.internalize_index_name(table, index_name)
630 631 632 633 634 635 636 637 638 639
      :
      m_ndb.internalize_table_name(index_name)); // Index is also a table

    if (internal_indexname.length())
    {
      Ndb_local_table_info * info=
        get_local_table_info(internal_indexname, false);
      if (info)
      {
	NdbTableImpl * tab= info->m_table_impl;
640
        if (tab->m_index == 0)
641
          tab->m_index= getIndexImpl(index_name, internal_indexname);
642
        if (tab->m_index != 0)
643
          tab->m_index->m_table= tab;
644 645 646 647 648
        return tab->m_index;
      }
    }
  }

649
  m_error.code= 4243;
650 651 652 653
  return 0;
}

#endif