create_index_executor.cpp 1.4 KB
Newer Older
羽飞's avatar
羽飞 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */

//
// Created by Wangyunlai on 2023/4/25.
//

#include "sql/executor/create_index_executor.h"
#include "sql/stmt/create_index_stmt.h"
羽飞's avatar
羽飞 已提交
17 18
#include "event/sql_event.h"
#include "event/session_event.h"
羽飞's avatar
羽飞 已提交
19 20
#include "session/session.h"
#include "common/log/log.h"
羽飞's avatar
羽飞 已提交
21
#include "storage/table/table.h"
羽飞's avatar
羽飞 已提交
22

羽飞's avatar
羽飞 已提交
23
RC CreateIndexExecutor::execute(SQLStageEvent *sql_event)
羽飞's avatar
羽飞 已提交
24
{
羽飞's avatar
羽飞 已提交
25 26
  Stmt *stmt = sql_event->stmt();
  Session *session = sql_event->session_event()->session();
羽飞's avatar
羽飞 已提交
27 28 29 30 31 32 33 34 35
  ASSERT(stmt->type() == StmtType::CREATE_INDEX, 
         "create index executor can not run this command: %d", static_cast<int>(stmt->type()));

  CreateIndexStmt *create_index_stmt = static_cast<CreateIndexStmt *>(stmt);
  
  Trx *trx = session->current_trx();
  Table *table = create_index_stmt->table();
  return table->create_index(trx, create_index_stmt->field_meta(), create_index_stmt->index_name().c_str());
}