OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parser::OptimizeTableStmt Class Reference

#include <ParserNode.h>

+ Inheritance diagram for Parser::OptimizeTableStmt:
+ Collaboration diagram for Parser::OptimizeTableStmt:

Public Member Functions

 OptimizeTableStmt (std::string *table, std::list< NameValueAssign * > *o)
 
 OptimizeTableStmt (const rapidjson::Value &payload)
 
const std::string getTableName () const
 
bool shouldVacuumDeletedRows () const
 
void execute (const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
 
- Public Member Functions inherited from Parser::DDLStmt
void setColumnDescriptor (ColumnDescriptor &cd, const ColumnDef *coldef)
 
- Public Member Functions inherited from Parser::Node
virtual ~Node ()
 

Private Attributes

std::unique_ptr< std::string > table_
 
std::list< std::unique_ptr
< NameValueAssign > > 
options_
 

Detailed Description

Definition at line 1239 of file ParserNode.h.

Constructor & Destructor Documentation

Parser::OptimizeTableStmt::OptimizeTableStmt ( std::string *  table,
std::list< NameValueAssign * > *  o 
)
inline

Definition at line 1241 of file ParserNode.h.

References options_, and table_.

1241  : table_(table) {
1242  if (!table_) {
1243  throw std::runtime_error("Table name is required for OPTIMIZE command.");
1244  }
1245  if (o) {
1246  for (const auto e : *o) {
1247  options_.emplace_back(e);
1248  }
1249  delete o;
1250  }
1251  }
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1269
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:1270
Parser::OptimizeTableStmt::OptimizeTableStmt ( const rapidjson::Value &  payload)

Definition at line 4977 of file ParserNode.cpp.

References CHECK, json_str(), options_, Parser::anonymous_namespace{ParserNode.cpp}::parse_options(), and table_.

4977  {
4978  CHECK(payload.HasMember("tableName"));
4979  table_ = std::make_unique<std::string>(json_str(payload["tableName"]));
4980  parse_options(payload, options_);
4981 }
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1269
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:46
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:1270
void parse_options(const rapidjson::Value &payload, std::list< std::unique_ptr< NameValueAssign >> &nameValueList, bool stringToNull=false, bool stringToInteger=false)
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

Member Function Documentation

void Parser::OptimizeTableStmt::execute ( const Catalog_Namespace::SessionInfo session,
bool  read_only_mode 
)
overridevirtual

Implements Parser::DDLStmt.

Definition at line 4999 of file ParserNode.cpp.

References Executor::clearExternalCaches(), AccessPrivileges::DELETE_FROM_TABLE, Catalog_Namespace::SessionInfo::getCatalog(), legacylockmgr::getExecuteReadLock(), Executor::getExecutor(), TableDescriptor::isView, TableOptimizer::recomputeMetadata(), shouldVacuumDeletedRows(), table_, Executor::UNITARY_EXECUTOR_ID, Parser::anonymous_namespace{ParserNode.cpp}::user_can_access_table(), and TableOptimizer::vacuumDeletedRows().

Referenced by heavydb.cursor.Cursor::executemany().

5000  {
5001  if (read_only_mode) {
5002  throw std::runtime_error("OPTIMIZE TABLE invalid in read only mode.");
5003  }
5004  auto& catalog = session.getCatalog();
5005 
5006  const auto execute_read_lock = legacylockmgr::getExecuteReadLock();
5007 
5008  const auto td_with_lock =
5010  catalog, *table_);
5011  const auto td = td_with_lock();
5012 
5013  if (!td || !user_can_access_table(session, td, AccessPrivileges::DELETE_FROM_TABLE)) {
5014  throw std::runtime_error("Table " + *table_ + " does not exist.");
5015  }
5016 
5017  if (td->isView) {
5018  throw std::runtime_error("OPTIMIZE TABLE command is not supported on views.");
5019  }
5020 
5021  // invalidate cached item
5022  Executor::clearExternalCaches(true, td, catalog.getDatabaseId());
5023 
5025  const TableOptimizer optimizer(td, executor, catalog);
5026  if (shouldVacuumDeletedRows()) {
5027  optimizer.vacuumDeletedRows();
5028  }
5029  optimizer.recomputeMetadata();
5030 }
auto getExecuteReadLock()
bool user_can_access_table(const Catalog_Namespace::SessionInfo &session_info, const TableDescriptor *td, const AccessPrivileges access_priv)
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1269
Driver for running cleanup processes on a table. TableOptimizer provides functions for various cleanu...
static std::shared_ptr< Executor > getExecutor(const ExecutorId id, const std::string &debug_dir="", const std::string &debug_file="", const SystemParameters &system_parameters=SystemParameters())
Definition: Execute.cpp:509
static const AccessPrivileges DELETE_FROM_TABLE
Definition: DBObject.h:163
Catalog & getCatalog() const
Definition: SessionInfo.h:75
bool shouldVacuumDeletedRows() const
Definition: ParserNode.h:1256
static void clearExternalCaches(bool for_update, const TableDescriptor *td, const int current_db_id)
Definition: Execute.h:438
static constexpr ExecutorId UNITARY_EXECUTOR_ID
Definition: Execute.h:423

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const std::string Parser::OptimizeTableStmt::getTableName ( ) const
inline

Definition at line 1254 of file ParserNode.h.

References table_.

1254 { return *(table_.get()); }
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1269
bool Parser::OptimizeTableStmt::shouldVacuumDeletedRows ( ) const
inline

Definition at line 1256 of file ParserNode.h.

References options_.

Referenced by execute().

1256  {
1257  for (const auto& e : options_) {
1258  if (boost::iequals(*(e->get_name()), "VACUUM")) {
1259  return true;
1260  }
1261  }
1262  return false;
1263  }
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:1270

+ Here is the caller graph for this function:

Member Data Documentation

std::list<std::unique_ptr<NameValueAssign> > Parser::OptimizeTableStmt::options_
private

Definition at line 1270 of file ParserNode.h.

Referenced by OptimizeTableStmt(), and shouldVacuumDeletedRows().

std::unique_ptr<std::string> Parser::OptimizeTableStmt::table_
private

Definition at line 1269 of file ParserNode.h.

Referenced by execute(), getTableName(), and OptimizeTableStmt().


The documentation for this class was generated from the following files: