OmniSciDB  c0231cc57d
 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 4624 of file ParserNode.cpp.

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

4624  {
4625  CHECK(payload.HasMember("tableName"));
4626  table_ = std::make_unique<std::string>(json_str(payload["tableName"]));
4627  parse_options(payload, options_);
4628 }
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:222

+ 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 4646 of file ParserNode.cpp.

References Catalog_Namespace::DBMetadata::dbId, AccessPrivileges::DELETE_FROM_TABLE, legacylockmgr::ExecutorOuterLock, Catalog_Namespace::SessionInfo::getCatalog(), Catalog_Namespace::Catalog::getCurrentDB(), 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().

4647  {
4648  if (read_only_mode) {
4649  throw std::runtime_error("OPTIMIZE TABLE invalid in read only mode.");
4650  }
4651  auto& catalog = session.getCatalog();
4652 
4653  const auto execute_read_lock =
4657 
4658  const auto td_with_lock =
4660  catalog, *table_);
4661  const auto td = td_with_lock();
4662 
4663  if (!td || !user_can_access_table(session, td, AccessPrivileges::DELETE_FROM_TABLE)) {
4664  throw std::runtime_error("Table " + *table_ + " does not exist.");
4665  }
4666 
4667  if (td->isView) {
4668  throw std::runtime_error("OPTIMIZE TABLE command is not supported on views.");
4669  }
4670 
4671  // invalidate cached item
4672  std::vector<int> table_key{catalog.getCurrentDB().dbId, td->tableId};
4673  ResultSetCacheInvalidator::invalidateCachesByTable(boost::hash_value(table_key));
4674 
4676  const TableOptimizer optimizer(td, executor, catalog);
4677  if (shouldVacuumDeletedRows()) {
4678  optimizer.vacuumDeletedRows();
4679  }
4680  optimizer.recomputeMetadata();
4681 }
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:477
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:376

+ 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: