Code_create_index.cpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:3k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* Copyright (C) 2003 MySQL AB
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.    This program is distributed in the hope that it will be useful,
  7.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  8.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9.    GNU General Public License for more details.
  10.    You should have received a copy of the GNU General Public License
  11.    along with this program; if not, write to the Free Software
  12.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  13. #include <common/StmtArea.hpp>
  14. #include "Code_create_index.hpp"
  15. #include "Code_root.hpp"
  16. // Plan_create_index
  17. Plan_create_index::~Plan_create_index()
  18. {
  19. }
  20. Plan_base*
  21. Plan_create_index::analyze(Ctx& ctx, Ctl& ctl)
  22. {
  23.     stmtArea().stmtInfo().setName(Stmt_name_create_index);
  24.     // analyze the table
  25.     ctx_assert(m_table != 0);
  26.     m_table->analyze(ctx, ctl);
  27.     if (! ctx.ok())
  28. return 0;
  29.     // analyze the columns
  30.     ctl.m_tableList.resize(1 + 1); // indexed from 1
  31.     ctl.m_tableList[1] = m_table;
  32.     for (unsigned i = 1, n = countColumn(); i <= n; i++) {
  33. Plan_idx_column* column = getColumn(i);
  34. column->analyze(ctx, ctl);
  35. if (! ctx.ok())
  36.     return 0;
  37.     }
  38.     return this;
  39. }
  40. void
  41. Plan_create_index::describe(Ctx& ctx)
  42. {
  43.     stmtArea().setFunction(ctx, "CREATE INDEX", SQL_DIAG_CREATE_INDEX);
  44. }
  45. Exec_base*
  46. Plan_create_index::codegen(Ctx& ctx, Ctl& ctl)
  47. {
  48.     Exec_create_index* exec = new Exec_create_index(ctl.m_execRoot);
  49.     ctl.m_execRoot->saveNode(exec);
  50.     const unsigned count = countColumn();
  51.     const char** attrList = new const char* [1 + count];
  52.     attrList[0] = 0; // unused
  53.     for (unsigned i = 1; i <= count; i++) {
  54. Plan_idx_column* column = getColumn(i);
  55. const char* cname = column->getName().c_str();
  56. attrList[i] = strcpy(new char[strlen(cname) + 1], cname);
  57.     }
  58.     Exec_create_index::Code& code = *new Exec_create_index::Code(m_name, m_table->getName(), m_type, count, attrList);
  59.     exec->setCode(code);
  60.     code.m_fragmentType = m_fragmentType;
  61.     code.m_logging = m_logging;
  62.     return exec;
  63. }
  64. void
  65. Plan_create_index::print(Ctx& ctx)
  66. {
  67.     ctx.print(" [create_index name=%s table=%s type=%d", m_name.c_str(), m_table->getName().c_str(), (int)m_type);
  68.     ctx.print(" [");
  69.     for (unsigned i = 1; i <= countColumn(); i++) {
  70. Plan_idx_column* column = getColumn(i);
  71. if (i > 1)
  72.     ctx.print(" ");
  73. column->print(ctx);
  74.     }
  75.     ctx.print("]");
  76. }
  77. // Exec_create_index
  78. Exec_create_index::Code::~Code()
  79. {
  80.     for (unsigned i = 1; i <= m_attrCount; i++) {
  81. delete[] m_attrList[i];
  82. m_attrList[i] = 0;
  83.     }
  84.     delete[] m_attrList;
  85. }
  86. Exec_create_index::Data::~Data()
  87. {
  88. }
  89. Exec_create_index::~Exec_create_index()
  90. {
  91. }
  92. void
  93. Exec_create_index::alloc(Ctx& ctx, Ctl& ctl)
  94. {
  95.     Data& data = *new Data;
  96.     setData(data);
  97. }
  98. void
  99. Exec_create_index::close(Ctx& ctx)
  100. {
  101. }
  102. void
  103. Exec_create_index::print(Ctx& ctx)
  104. {
  105.     const Code& code = getCode();
  106.     ctx.print(" [create_index %s]", code.m_tableName.c_str());
  107. }