OmniSciDB  a5dc49c757
 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 4998 of file ParserNode.cpp.

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

4998  {
4999  CHECK(payload.HasMember("tableName"));
5000  table_ = std::make_unique<std::string>(json_str(payload["tableName"]));
5001  parse_options(payload, options_);
5002 }
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 5020 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().

5021  {
5022  if (read_only_mode) {
5023  throw std::runtime_error("OPTIMIZE TABLE invalid in read only mode.");
5024  }
5025  auto& catalog = session.getCatalog();
5026 
5027  const auto execute_read_lock = legacylockmgr::getExecuteReadLock();
5028 
5029  const auto td_with_lock =
5031  catalog, *table_);
5032  const auto td = td_with_lock();
5033 
5034  if (!td || !user_can_access_table(session, td, AccessPrivileges::DELETE_FROM_TABLE)) {
5035  throw std::runtime_error("Table " + *table_ + " does not exist.");
5036  }
5037 
5038  if (td->isView) {
5039  throw std::runtime_error("OPTIMIZE TABLE command is not supported on views.");
5040  }
5041 
5042  // invalidate cached item
5043  Executor::clearExternalCaches(true, td, catalog.getDatabaseId());
5044 
5046  const TableOptimizer optimizer(td, executor, catalog);
5047  if (shouldVacuumDeletedRows()) {
5048  optimizer.vacuumDeletedRows();
5049  }
5050  optimizer.recomputeMetadata();
5051 }
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:513
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: