Merge pull request #58390 from bharatnc/ncb/system-database-engines

add table system.database_engines
This commit is contained in:
Alexey Milovidov 2023-12-31 12:38:46 +01:00 committed by GitHub
commit c29b5e351e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 83 additions and 0 deletions

View File

@ -0,0 +1,26 @@
---
slug: /en/operations/system-tables/database_engines
---
# database_engines
Contains the list of database engines supported by the server.
This table contains the following columns (the column type is shown in brackets):
- `name` (String) — The name of database engine.
Example:
``` sql
SELECT *
FROM system.database_engines
WHERE name in ('Atomic', 'Lazy', 'Ordinary')
```
``` text
┌─name─────┐
│ Ordinary │
│ Atomic │
│ Lazy │
└──────────┘
```

View File

@ -155,6 +155,7 @@ namespace
"formats", "formats",
"privileges", "privileges",
"data_type_families", "data_type_families",
"database_engines",
"table_engines", "table_engines",
"table_functions", "table_functions",
"aggregate_function_combinators", "aggregate_function_combinators",

View File

@ -77,6 +77,7 @@ static String getLoadSuggestionQuery(Int32 suggestion_limit, bool basic_suggesti
}; };
add_column("name", "functions", false, {}); add_column("name", "functions", false, {});
add_column("name", "database_engines", false, {});
add_column("name", "table_engines", false, {}); add_column("name", "table_engines", false, {});
add_column("name", "formats", false, {}); add_column("name", "formats", false, {});
add_column("name", "table_functions", false, {}); add_column("name", "table_functions", false, {});

View File

@ -52,6 +52,8 @@ public:
void registerDatabase(const std::string & name, CreatorFn creator_fn); void registerDatabase(const std::string & name, CreatorFn creator_fn);
const DatabaseEngines & getDatabaseEngines() const { return database_engines; }
private: private:
DatabaseEngines database_engines; DatabaseEngines database_engines;
}; };

View File

@ -0,0 +1,25 @@
#include <DataTypes/DataTypeString.h>
#include <DataTypes/DataTypesNumber.h>
#include <Databases/DatabaseFactory.h>
#include <Storages/System/StorageSystemDatabaseEngines.h>
namespace DB
{
NamesAndTypesList StorageSystemDatabaseEngines::getNamesAndTypes()
{
return {
{"name", std::make_shared<DataTypeString>()},
};
}
void StorageSystemDatabaseEngines::fillData(MutableColumns & res_columns, ContextPtr, const SelectQueryInfo &) const
{
for (const auto & [engine, _] : DatabaseFactory::instance().getDatabaseEngines())
{
int i = 0;
res_columns[i++]->insert(engine);
}
}
}

View File

@ -0,0 +1,22 @@
#pragma once
#include <DataTypes/DataTypeString.h>
#include <Storages/System/IStorageSystemOneBlock.h>
namespace DB
{
class StorageSystemDatabaseEngines final : public IStorageSystemOneBlock<StorageSystemDatabaseEngines>
{
protected:
void fillData(MutableColumns & res_columns, ContextPtr context, const SelectQueryInfo & query_info) const override;
using IStorageSystemOneBlock::IStorageSystemOneBlock;
public:
std::string getName() const override { return "SystemDatabaseEngines"; }
static NamesAndTypesList getNamesAndTypes();
};
}

View File

@ -45,6 +45,7 @@
#include <Storages/System/StorageSystemSettings.h> #include <Storages/System/StorageSystemSettings.h>
#include <Storages/System/StorageSystemSettingsChanges.h> #include <Storages/System/StorageSystemSettingsChanges.h>
#include <Storages/System/StorageSystemMergeTreeSettings.h> #include <Storages/System/StorageSystemMergeTreeSettings.h>
#include <Storages/System/StorageSystemDatabaseEngines.h>
#include <Storages/System/StorageSystemTableEngines.h> #include <Storages/System/StorageSystemTableEngines.h>
#include <Storages/System/StorageSystemTableFunctions.h> #include <Storages/System/StorageSystemTableFunctions.h>
#include <Storages/System/StorageSystemTables.h> #include <Storages/System/StorageSystemTables.h>
@ -132,6 +133,7 @@ void attachSystemTablesServer(ContextPtr context, IDatabase & system_database, b
attach<StorageSystemAggregateFunctionCombinators>(context, system_database, "aggregate_function_combinators"); attach<StorageSystemAggregateFunctionCombinators>(context, system_database, "aggregate_function_combinators");
attach<StorageSystemDataTypeFamilies>(context, system_database, "data_type_families"); attach<StorageSystemDataTypeFamilies>(context, system_database, "data_type_families");
attach<StorageSystemCollations>(context, system_database, "collations"); attach<StorageSystemCollations>(context, system_database, "collations");
attach<StorageSystemDatabaseEngines>(context, system_database, "database_engines");
attach<StorageSystemTableEngines>(context, system_database, "table_engines"); attach<StorageSystemTableEngines>(context, system_database, "table_engines");
attach<StorageSystemContributors>(context, system_database, "contributors"); attach<StorageSystemContributors>(context, system_database, "contributors");
attach<StorageSystemUsers>(context, system_database, "users"); attach<StorageSystemUsers>(context, system_database, "users");

View File

@ -0,0 +1,3 @@
Atomic
Lazy
Ordinary

View File

@ -0,0 +1 @@
SELECT * FROM system.database_engines WHERE name IN ('Atomic', 'Lazy', 'Ordinary') ORDER BY name;