2016-03-26 03:03:50 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/types.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/IAST.h>
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <Storages/IStorage_fwd.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Databases/IDatabase.h>
|
2019-08-28 13:21:19 +00:00
|
|
|
#include <mutex>
|
2016-03-26 03:03:50 +00:00
|
|
|
|
2017-05-23 18:33:48 +00:00
|
|
|
|
2017-04-17 11:56:55 +00:00
|
|
|
/// General functionality for several different database engines.
|
2016-03-26 03:03:50 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-10-29 16:47:57 +00:00
|
|
|
void applyMetadataChangesToCreateQuery(const ASTPtr & query, const StorageInMemoryMetadata & metadata);
|
2021-11-19 10:25:55 +00:00
|
|
|
ASTPtr getCreateQueryFromStorage(const StoragePtr & storage, const ASTPtr & ast_storage, bool only_ordinary, uint32_t max_parser_depth, bool throw_on_error);
|
2021-10-29 16:47:57 +00:00
|
|
|
|
2022-06-09 16:19:35 +00:00
|
|
|
/// Cleans a CREATE QUERY from temporary flags like "IF NOT EXISTS", "OR REPLACE", "AS SELECT" (for non-views), etc.
|
|
|
|
void cleanupObjectDefinitionFromTemporaryFlags(ASTCreateQuery & query);
|
|
|
|
|
2017-05-23 18:33:48 +00:00
|
|
|
class Context;
|
|
|
|
|
2018-03-23 20:46:43 +00:00
|
|
|
/// A base class for databases that manage their own list of tables.
|
2021-04-10 23:33:54 +00:00
|
|
|
class DatabaseWithOwnTablesBase : public IDatabase, protected WithContext
|
2018-03-23 20:46:43 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-04-10 23:33:54 +00:00
|
|
|
bool isTableExist(const String & table_name, ContextPtr context) const override;
|
2018-03-23 20:46:43 +00:00
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
StoragePtr tryGetTable(const String & table_name, ContextPtr context) const override;
|
2018-03-23 20:46:43 +00:00
|
|
|
|
2020-04-23 16:51:48 +00:00
|
|
|
bool empty() const override;
|
2018-03-23 20:46:43 +00:00
|
|
|
|
2021-11-10 13:13:27 +00:00
|
|
|
void attachTable(ContextPtr context, const String & table_name, const StoragePtr & table, const String & relative_table_path) override;
|
2018-03-23 20:46:43 +00:00
|
|
|
|
2021-11-10 13:13:27 +00:00
|
|
|
StoragePtr detachTable(ContextPtr context, const String & table_name) override;
|
2018-03-23 20:46:43 +00:00
|
|
|
|
2021-08-03 09:18:09 +00:00
|
|
|
DatabaseTablesIteratorPtr getTablesIterator(ContextPtr context, const FilterByNameFunction & filter_by_table_name) const override;
|
2019-10-10 17:33:01 +00:00
|
|
|
|
2022-05-31 09:33:23 +00:00
|
|
|
DatabaseTablesIteratorPtr getTablesIteratorForBackup(const BackupEntriesCollector & backup_entries_collector) const override;
|
2022-06-14 08:53:22 +00:00
|
|
|
void checkCreateTableQueryForBackup(const ASTPtr & create_table_query, const BackupEntriesCollector & backup_entries_collector) const override;
|
|
|
|
void createTableRestoredFromBackup(const ASTPtr & create_table_query, const RestorerFromBackup & restorer) override;
|
2018-03-23 20:46:43 +00:00
|
|
|
|
2022-05-29 19:53:56 +00:00
|
|
|
void shutdown() override;
|
|
|
|
|
2020-05-28 20:10:45 +00:00
|
|
|
~DatabaseWithOwnTablesBase() override;
|
2018-03-23 20:56:45 +00:00
|
|
|
|
2018-03-23 20:46:43 +00:00
|
|
|
protected:
|
|
|
|
Tables tables;
|
2019-11-06 16:05:04 +00:00
|
|
|
Poco::Logger * log;
|
2018-03-23 20:46:43 +00:00
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
DatabaseWithOwnTablesBase(const String & name_, const String & logger, ContextPtr context);
|
2020-01-30 12:51:47 +00:00
|
|
|
|
2020-04-22 20:43:10 +00:00
|
|
|
void attachTableUnlocked(const String & table_name, const StoragePtr & table, std::unique_lock<std::mutex> & lock);
|
|
|
|
StoragePtr detachTableUnlocked(const String & table_name, std::unique_lock<std::mutex> & lock);
|
|
|
|
StoragePtr getTableUnlocked(const String & table_name, std::unique_lock<std::mutex> & lock) const;
|
2018-03-23 20:46:43 +00:00
|
|
|
};
|
|
|
|
|
2016-03-26 03:03:50 +00:00
|
|
|
}
|