OmniSciDB  c1a53651b2
 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 1252 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 1254 of file ParserNode.h.

References options_, and table_.

1254  : table_(table) {
1255  if (!table_) {
1256  throw std::runtime_error("Table name is required for OPTIMIZE command.");
1257  }
1258  if (o) {
1259  for (const auto e : *o) {
1260  options_.emplace_back(e);
1261  }
1262  delete o;
1263  }
1264  }
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1282
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:1283
Parser::OptimizeTableStmt::OptimizeTableStmt ( const rapidjson::Value &  payload)

Definition at line 4651 of file ParserNode.cpp.

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

4651  {
4652  CHECK(payload.HasMember("tableName"));
4653  table_ = std::make_unique<std::string>(json_str(payload["tableName"]));
4654  parse_options(payload, options_);
4655 }
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1282
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:1283
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 4673 of file ParserNode.cpp.

References AccessPrivileges::DELETE_FROM_TABLE, legacylockmgr::ExecutorOuterLock, Catalog_Namespace::SessionInfo::getCatalog(), Executor::getExecutor(), legacylockmgr::LockMgr< MutexType, KeyType >::getMutex(), CacheInvalidator< CACHE_HOLDING_TYPES >::invalidateCachesByTable(), TableDescriptor::isView, TableOptimizer::recomputeMetadata(), shouldVacuumDeletedRows(), table_, TableDescriptor::tableId, Executor::UNITARY_EXECUTOR_ID, Parser::anonymous_namespace{ParserNode.cpp}::user_can_access_table(), and TableOptimizer::vacuumDeletedRows().

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

4674  {
4675  if (read_only_mode) {
4676  throw std::runtime_error("OPTIMIZE TABLE invalid in read only mode.");
4677  }
4678  auto& catalog = session.getCatalog();
4679 
4680  const auto execute_read_lock =
4684 
4685  const auto td_with_lock =
4687  catalog, *table_);
4688  const auto td = td_with_lock();
4689 
4690  if (!td || !user_can_access_table(session, td, AccessPrivileges::DELETE_FROM_TABLE)) {
4691  throw std::runtime_error("Table " + *table_ + " does not exist.");
4692  }
4693 
4694  if (td->isView) {
4695  throw std::runtime_error("OPTIMIZE TABLE command is not supported on views.");
4696  }
4697 
4698  // invalidate cached item
4699  std::vector<int> table_key{catalog.getCurrentDB().dbId, td->tableId};
4700  ResultSetCacheInvalidator::invalidateCachesByTable(boost::hash_value(table_key));
4701 
4703  const TableOptimizer optimizer(td, executor, catalog);
4704  if (shouldVacuumDeletedRows()) {
4705  optimizer.vacuumDeletedRows();
4706  }
4707  optimizer.recomputeMetadata();
4708 }
static std::shared_ptr< WrapperType< MutexType > > getMutex(const LockType lockType, const KeyType &key)
static void invalidateCachesByTable(size_t table_key)
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:1282
Driver for running cleanup processes on a table. TableOptimizer provides functions for various cleanu...
std::shared_lock< T > shared_lock
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:475
static const AccessPrivileges DELETE_FROM_TABLE
Definition: DBObject.h:163
Catalog & getCatalog() const
Definition: SessionInfo.h:75
bool shouldVacuumDeletedRows() const
Definition: ParserNode.h:1269
static const ExecutorId UNITARY_EXECUTOR_ID
Definition: Execute.h:373

+ 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 1267 of file ParserNode.h.

References table_.

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

Definition at line 1269 of file ParserNode.h.

References options_.

Referenced by execute().

1269  {
1270  for (const auto& e : options_) {
1271  if (boost::iequals(*(e->get_name()), "VACUUM")) {
1272  return true;
1273  }
1274  }
1275  return false;
1276  }
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:1283

+ Here is the caller graph for this function:

Member Data Documentation

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

Definition at line 1283 of file ParserNode.h.

Referenced by OptimizeTableStmt(), and shouldVacuumDeletedRows().

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

Definition at line 1282 of file ParserNode.h.

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


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