Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9815 from Mytherin/duckdboptimizers
Add duckdb_optimizers function
- Loading branch information
Showing
7 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "duckdb/function/table/system_functions.hpp" | ||
#include "duckdb/common/types/chunk_collection.hpp" | ||
#include "duckdb/main/config.hpp" | ||
#include "duckdb/main/client_context.hpp" | ||
#include "duckdb/common/enum_util.hpp" | ||
#include "duckdb/common/enums/optimizer_type.hpp" | ||
|
||
namespace duckdb { | ||
|
||
struct DuckDBOptimizersData : public GlobalTableFunctionState { | ||
DuckDBOptimizersData() : offset(0) { | ||
} | ||
|
||
vector<string> optimizers; | ||
idx_t offset; | ||
}; | ||
|
||
static unique_ptr<FunctionData> DuckDBOptimizersBind(ClientContext &context, TableFunctionBindInput &input, | ||
vector<LogicalType> &return_types, vector<string> &names) { | ||
names.emplace_back("name"); | ||
return_types.emplace_back(LogicalType::VARCHAR); | ||
|
||
return nullptr; | ||
} | ||
|
||
unique_ptr<GlobalTableFunctionState> DuckDBOptimizersInit(ClientContext &context, TableFunctionInitInput &input) { | ||
auto result = make_uniq<DuckDBOptimizersData>(); | ||
result->optimizers = ListAllOptimizers(); | ||
return std::move(result); | ||
} | ||
|
||
void DuckDBOptimizersFunction(ClientContext &context, TableFunctionInput &data_p, DataChunk &output) { | ||
auto &data = data_p.global_state->Cast<DuckDBOptimizersData>(); | ||
if (data.offset >= data.optimizers.size()) { | ||
// finished returning values | ||
return; | ||
} | ||
// start returning values | ||
// either fill up the chunk or return all the remaining columns | ||
idx_t count = 0; | ||
while (data.offset < data.optimizers.size() && count < STANDARD_VECTOR_SIZE) { | ||
auto &entry = data.optimizers[data.offset++]; | ||
|
||
// return values: | ||
// name, LogicalType::VARCHAR | ||
output.SetValue(0, count, Value(entry)); | ||
count++; | ||
} | ||
output.SetCardinality(count); | ||
} | ||
|
||
void DuckDBOptimizersFun::RegisterFunction(BuiltinFunctions &set) { | ||
set.AddFunction( | ||
TableFunction("duckdb_optimizers", {}, DuckDBOptimizersFunction, DuckDBOptimizersBind, DuckDBOptimizersInit)); | ||
} | ||
|
||
} // namespace duckdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# name: test/sql/table_function/duckdb_optimizers.test | ||
# description: Test duckdb_optimizers function | ||
# group: [table_function] | ||
|
||
statement ok | ||
SELECT * FROM duckdb_optimizers(); | ||
|
||
query I | ||
SELECT name FROM duckdb_optimizers() WHERE name='join_order'; | ||
---- | ||
join_order |