From ff8dd3a773f11d491258664f1387a50f31db9573 Mon Sep 17 00:00:00 2001 From: Alex Kasko Date: Sat, 6 Jun 2026 23:30:44 +0100 Subject: [PATCH] Remove deprecated API usage --- database-connector | 2 +- src/CMakeLists.txt | 1 + src/dbconnector/CMakeLists.txt | 16 +++++++++++ src/include/postgres_binary_writer.hpp | 4 +-- src/include/postgres_utils.hpp | 6 +++++ src/postgres_attach.cpp | 14 +++++----- src/postgres_aws.cpp | 7 ++--- src/postgres_copy_to.cpp | 9 ++++--- src/postgres_filter_pushdown.cpp | 9 ++++--- src/postgres_scanner.cpp | 7 ++--- src/postgres_text_reader.cpp | 14 +++++----- src/postgres_utils.cpp | 35 +++++++++++++++++++++++-- src/storage/postgres_catalog_set.cpp | 5 ++-- src/storage/postgres_configure_pool.cpp | 34 ++++++++++++------------ src/storage/postgres_delete.cpp | 5 ++-- src/storage/postgres_index_set.cpp | 11 +++++--- src/storage/postgres_insert.cpp | 2 +- src/storage/postgres_schema_set.cpp | 11 +++++--- src/storage/postgres_table_set.cpp | 33 ++++++++++++----------- src/storage/postgres_type_set.cpp | 19 ++++++++------ src/storage/postgres_update.cpp | 17 ++++++------ 21 files changed, 169 insertions(+), 92 deletions(-) create mode 100644 src/dbconnector/CMakeLists.txt diff --git a/database-connector b/database-connector index 43e79061e..cee82899d 160000 --- a/database-connector +++ b/database-connector @@ -1 +1 @@ -Subproject commit 43e79061e5d00411612fee98482586a0e7a756cd +Subproject commit cee82899dc2df62e1d922f46a0d6e875ff33b732 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1dc8d444e..63d27c0b2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,6 @@ include_directories(include) +add_subdirectory(dbconnector) add_subdirectory(storage) add_library( diff --git a/src/dbconnector/CMakeLists.txt b/src/dbconnector/CMakeLists.txt new file mode 100644 index 000000000..7c730e228 --- /dev/null +++ b/src/dbconnector/CMakeLists.txt @@ -0,0 +1,16 @@ +set(POSTGRES_DBCONNECTOR_PATH + "${CMAKE_CURRENT_LIST_DIR}/../../database-connector") + +add_library( + postgres_ext_dbconnector OBJECT + ${POSTGRES_DBCONNECTOR_PATH}/src/query/query_writer.cpp + # ${POSTGRES_DBCONNECTOR_PATH}/src/table_scan/filter_pushdown.cpp + # ${POSTGRES_DBCONNECTOR_PATH}/src/table_scan/filter_util.cpp + # ${POSTGRES_DBCONNECTOR_PATH}/src/optimizer/aggregate_optimizer.cpp + # ${POSTGRES_DBCONNECTOR_PATH}/src/optimizer/optimizer_util.cpp + # ${POSTGRES_DBCONNECTOR_PATH}/src/optimizer/order_by_and_limit_optimizer.cpp +) + +set(ALL_OBJECT_FILES + ${ALL_OBJECT_FILES} $ + PARENT_SCOPE) diff --git a/src/include/postgres_binary_writer.hpp b/src/include/postgres_binary_writer.hpp index cff8e8cb3..1d951afa7 100644 --- a/src/include/postgres_binary_writer.hpp +++ b/src/include/postgres_binary_writer.hpp @@ -237,7 +237,7 @@ class PostgresBinaryWriter { void WriteArray(Vector &col, idx_t r, const vector &dimensions, idx_t depth, uint32_t count) { auto list_data = FlatVector::GetData(col); - auto &child_vector = ListVector::GetEntry(col); + auto &child_vector = ListVector::GetChildMutable(col); for (idx_t i = 0; i < count; i++) { auto list_entry = list_data[r + i]; if (list_entry.length != dimensions[depth]) { @@ -398,7 +398,7 @@ class PostgresBinaryWriter { while (current_vector.get().GetType().id() == LogicalTypeId::LIST) { auto current_entry = FlatVector::GetData(current_vector.get())[current_position]; dimensions.push_back(current_entry.length); - current_vector = ListVector::GetEntry(current_vector.get()); + current_vector = ListVector::GetChild(current_vector.get()); current_position = current_entry.offset; } diff --git a/src/include/postgres_utils.hpp b/src/include/postgres_utils.hpp index e28797bf7..84c07968b 100644 --- a/src/include/postgres_utils.hpp +++ b/src/include/postgres_utils.hpp @@ -79,6 +79,12 @@ class PostgresUtils { static string EscapeConnectionString(const string &input); static string ExtractConnectionOption(const KeyValueSecret &kv_secret, const string &name); + static string WriteLiteral(const string &identifier); + static string WriteIdentifier(const string &identifier); + +private: + static string EscapeQuotes(const string &text, char quote); + static string WriteQuoted(const string &text, char quote); }; } // namespace duckdb diff --git a/src/postgres_attach.cpp b/src/postgres_attach.cpp index 4f1d01ce5..a9fc5a39f 100644 --- a/src/postgres_attach.cpp +++ b/src/postgres_attach.cpp @@ -1,9 +1,11 @@ #include "duckdb.hpp" #include "duckdb/parser/parsed_data/create_table_function_info.hpp" + #include "postgres_filter_pushdown.hpp" #include "postgres_scanner.hpp" #include "postgres_result.hpp" +#include "postgres_utils.hpp" namespace duckdb { @@ -57,7 +59,7 @@ WHERE relkind = 'r' AND attnum > 0 AND nspname = %s GROUP BY relname ORDER BY relname; )", - KeywordHelper::WriteQuoted(data.source_schema)); + PostgresUtils::WriteLiteral(data.source_schema)); auto res = conn.Query(context, fetch_table_query); for (idx_t row = 0; row < PQntuples(res->res); row++) { auto table_name = res->GetString(row, 0); @@ -68,9 +70,9 @@ ORDER BY relname; query = "CREATE VIEW IF NOT EXISTS "; } if (!data.sink_schema.empty()) { - query += KeywordHelper::WriteQuoted(data.sink_schema, '"') + "."; + query += PostgresUtils::WriteIdentifier(data.sink_schema) + "."; } - query += KeywordHelper::WriteQuoted(table_name, '"'); + query += PostgresUtils::WriteIdentifier(table_name); query += " AS SELECT * FROM "; if (data.filter_pushdown) { query += "postgres_scan_pushdown"; @@ -78,11 +80,11 @@ ORDER BY relname; query += "postgres_scan"; } query += "("; - query += KeywordHelper::WriteQuoted(data.dsn); + query += PostgresUtils::WriteLiteral(data.dsn); query += ", "; - query += KeywordHelper::WriteQuoted(data.source_schema); + query += PostgresUtils::WriteLiteral(data.source_schema); query += ", "; - query += KeywordHelper::WriteQuoted(table_name); + query += PostgresUtils::WriteLiteral(table_name); query += ");"; dconn.Query(query); } diff --git a/src/postgres_aws.cpp b/src/postgres_aws.cpp index cb2de72eb..79776dc32 100644 --- a/src/postgres_aws.cpp +++ b/src/postgres_aws.cpp @@ -3,9 +3,10 @@ #include #include +#include "duckdb/parser/keyword_helper.hpp" + #include "dbconnector/defer.hpp" -#include "duckdb/parser/keyword_helper.hpp" #include "postgres_secrets.hpp" #include "postgres_utils.hpp" @@ -29,7 +30,7 @@ static std::string MakeCreateSecretQuery(const std::string &template_secret_name for (auto &en : kv_secret.secret_map) { query += " " + en.first + " " + en.second.ToSQLString() + ",\n"; } - query += " RDS_TEMPLATE_SECRET_NAME " + KeywordHelper::WriteQuoted(template_secret_name, '\'') + "\n"; + query += " RDS_TEMPLATE_SECRET_NAME " + PostgresUtils::WriteLiteral(template_secret_name) + "\n"; query += ")"; return query; } @@ -71,7 +72,7 @@ std::string PostgresAws::GenerateRdsAuthToken(AttachedDatabase &attached_db, std::string create_secret_query = MakeCreateSecretQuery(token_config.rds_secret_name, secret_name, kv_template_secret); - std::string quoted_secret_name = KeywordHelper::WriteQuoted(secret_name, '"'); + std::string quoted_secret_name = PostgresUtils::WriteIdentifier(secret_name); RunQuery(conn, create_secret_query, "error creating RDS secret from template: " + token_config.rds_secret_name); auto deferred_drop_secret = dbconnector::Defer([&conn, quoted_secret_name] { conn.Query("DROP SECRET " + quoted_secret_name); }); diff --git a/src/postgres_copy_to.cpp b/src/postgres_copy_to.cpp index 501324600..7796a126a 100644 --- a/src/postgres_copy_to.cpp +++ b/src/postgres_copy_to.cpp @@ -1,6 +1,7 @@ #include "duckdb/common/vector/list_vector.hpp" #include "duckdb/common/vector/map_vector.hpp" #include "duckdb/common/vector/struct_vector.hpp" + #include "postgres_connection.hpp" #include "postgres_binary_writer.hpp" #include "postgres_text_writer.hpp" @@ -31,16 +32,16 @@ void PostgresConnection::BeginCopyTo(ClientContext &context, PostgresCopyState & const vector &column_names) { string query = "COPY "; if (!schema_name.empty()) { - query += KeywordHelper::WriteQuoted(schema_name, '"') + "."; + query += PostgresUtils::WriteIdentifier(schema_name) + "."; } - query += KeywordHelper::WriteQuoted(table_name, '"') + " "; + query += PostgresUtils::WriteIdentifier(table_name) + " "; if (!column_names.empty()) { query += "("; for (idx_t c = 0; c < column_names.size(); c++) { if (c > 0) { query += ", "; } - query += KeywordHelper::WriteQuoted(column_names[c], '"'); + query += PostgresUtils::WriteIdentifier(column_names[c]); } query += ") "; } @@ -172,7 +173,7 @@ void CastToPostgresVarchar(ClientContext &context, Vector &input, Vector &result void CastListToPostgresArray(ClientContext &context, Vector &input, Vector &varchar_vector, idx_t size) { // cast child list - auto &child_data = ListVector::GetEntry(input); + auto &child_data = ListVector::GetChildMutable(input); auto child_count = ListVector::GetListSize(input); bool skip_quoting = child_data.GetType().id() == LogicalTypeId::LIST; // Do not quote dimensions in multi-D arrays Vector child_varchar(LogicalType::VARCHAR, child_count); diff --git a/src/postgres_filter_pushdown.cpp b/src/postgres_filter_pushdown.cpp index 23916444a..400ecbf1e 100644 --- a/src/postgres_filter_pushdown.cpp +++ b/src/postgres_filter_pushdown.cpp @@ -1,4 +1,5 @@ #include "postgres_filter_pushdown.hpp" + #include "duckdb/parser/keyword_helper.hpp" #include "duckdb/function/scalar/struct_utils.hpp" #include "duckdb/planner/expression/bound_comparison_expression.hpp" @@ -9,6 +10,8 @@ #include "duckdb/planner/filter/table_filter_functions.hpp" #include "duckdb/common/enum_util.hpp" +#include "postgres_utils.hpp" + namespace duckdb { string PostgresFilterPushdown::CreateExpression(const string &column_name, @@ -64,7 +67,7 @@ string TransformLiteral(const Value &val) { case LogicalTypeId::BLOB: return TransformBlob(StringValue::Get(val)); default: - return KeywordHelper::WriteQuoted(val.ToString()); + return PostgresUtils::WriteLiteral(val.ToString()); } } @@ -103,7 +106,7 @@ string PostgresFilterPushdown::TransformExpressionSubject(const string &column_n if (struct_type.id() != LogicalTypeId::STRUCT || StructType::IsUnnamed(struct_type)) { return string(); } - auto child_name = KeywordHelper::WriteQuoted(StructType::GetChildName(struct_type, child_idx), '\"'); + auto child_name = PostgresUtils::WriteIdentifier(StructType::GetChildName(struct_type, child_idx)); return "(" + parent_name + ")." + child_name; } default: @@ -218,7 +221,7 @@ string PostgresFilterPushdown::TransformFilters(const vector &column_i if (IsVirtualColumn(column_id)) { column_name = "ctid"; } else { - column_name = KeywordHelper::WriteQuoted(names[column_id], '"'); + column_name = PostgresUtils::WriteIdentifier(names[column_id]); } auto &filter = entry.Filter(); auto filter_text = TransformFilter(column_name, filter, column_id); diff --git a/src/postgres_scanner.cpp b/src/postgres_scanner.cpp index c0ea75e18..07233f179 100644 --- a/src/postgres_scanner.cpp +++ b/src/postgres_scanner.cpp @@ -6,6 +6,7 @@ #include "duckdb/common/shared_ptr.hpp" #include "duckdb/common/helper.hpp" #include "duckdb/parser/parsed_data/create_table_function_info.hpp" + #include "postgres_oauth.hpp" #include "postgres_filter_pushdown.hpp" #include "postgres_scanner.hpp" @@ -243,7 +244,7 @@ static void PostgresInitInternal(ClientContext &context, const PostgresBindData col_names += "ctid"; } } else { - col_names += KeywordHelper::WriteQuoted(bind_data->names[column_id], '"'); + col_names += PostgresUtils::WriteIdentifier(bind_data->names[column_id]); if (bind_data->postgres_types[column_id].info == PostgresTypeAnnotation::CAST_TO_VARCHAR) { col_names += "::VARCHAR"; } else if (bind_data->types[column_id].id() == LogicalTypeId::LIST) { @@ -290,8 +291,8 @@ static void PostgresInitInternal(ClientContext &context, const PostgresBindData } else { query = StringUtil::Format(R"(SELECT %s FROM %s.%s %s%s)", col_names, - KeywordHelper::WriteQuoted(bind_data->schema_name, '"'), - KeywordHelper::WriteQuoted(bind_data->table_name, '"'), filter, bind_data->limit); + PostgresUtils::WriteIdentifier(bind_data->schema_name), + PostgresUtils::WriteIdentifier(bind_data->table_name), filter, bind_data->limit); } if (!bind_data->use_text_protocol) { query = StringUtil::Format(R"(COPY (%s) TO STDOUT (FORMAT "binary");)", query); diff --git a/src/postgres_text_reader.cpp b/src/postgres_text_reader.cpp index 132b0b585..f1c70640f 100644 --- a/src/postgres_text_reader.cpp +++ b/src/postgres_text_reader.cpp @@ -31,7 +31,7 @@ struct PostgresListParser { void AddString(const string &str, bool "ed) { if (size >= capacity) { - vector.Resize(capacity, capacity * 2); + vector.Reserve(capacity * 2); capacity *= 2; } if (!quoted && str == "NULL") { @@ -204,7 +204,7 @@ void ParsePostgresCTID(PostgresCTIDParser &ctid_parser, string_t list) { void PostgresTextReader::ConvertList(Vector &source, Vector &target, const PostgresType &postgres_type, idx_t count) { // lists have the format {1, 2, 3} UnifiedVectorFormat vdata; - source.ToUnifiedFormat(count, vdata); + source.ToUnifiedFormat(vdata); auto strings = UnifiedVectorFormat::GetData(vdata); auto list_data = FlatVector::GetDataMutable(target); @@ -221,7 +221,7 @@ void PostgresTextReader::ConvertList(Vector &source, Vector &target, const Postg list_data[i].length = list_parser.size - list_data[i].offset; } if (list_parser.size > 0) { - auto &target_child = ListVector::GetEntry(target); + auto &target_child = ListVector::GetChildMutable(target); ListVector::Reserve(target, list_parser.size); ConvertVector(list_parser.vector, target_child, postgres_type.children.empty() ? PostgresType() : postgres_type.children[0], list_parser.size); @@ -232,7 +232,7 @@ void PostgresTextReader::ConvertList(Vector &source, Vector &target, const Postg void PostgresTextReader::ConvertStruct(Vector &source, Vector &target, const PostgresType &postgres_type, idx_t count) { // structs have the format (1, 2, 3) UnifiedVectorFormat vdata; - source.ToUnifiedFormat(count, vdata); + source.ToUnifiedFormat(vdata); auto strings = UnifiedVectorFormat::GetData(vdata); auto &children = StructVector::GetEntries(target); @@ -257,7 +257,7 @@ void PostgresTextReader::ConvertStruct(Vector &source, Vector &target, const Pos void PostgresTextReader::ConvertCTID(Vector &source, Vector &target, idx_t count) { // ctids have the format (page_index, row_in_page) UnifiedVectorFormat vdata; - source.ToUnifiedFormat(count, vdata); + source.ToUnifiedFormat(vdata); auto strings = UnifiedVectorFormat::GetData(vdata); auto result = FlatVector::GetDataMutable(target); @@ -278,7 +278,7 @@ void PostgresTextReader::ConvertCTID(Vector &source, Vector &target, idx_t count void PostgresTextReader::ConvertBlob(Vector &source, Vector &target, idx_t count) { // ctids have the format (page_index, row_in_page) UnifiedVectorFormat vdata; - source.ToUnifiedFormat(count, vdata); + source.ToUnifiedFormat(vdata); auto strings = UnifiedVectorFormat::GetData(vdata); auto result = FlatVector::GetDataMutable(target); @@ -311,7 +311,7 @@ static void ConvertGeometry(Vector &source, Vector &target, idx_t count) { // Geometry is encoded in HEXWKB format UnifiedVectorFormat vdata; - source.ToUnifiedFormat(count, vdata); + source.ToUnifiedFormat(vdata); const auto strings = UnifiedVectorFormat::GetData(vdata); const auto result = FlatVector::GetDataMutable(target); diff --git a/src/postgres_utils.cpp b/src/postgres_utils.cpp index d5fe93a40..f4525a8fe 100644 --- a/src/postgres_utils.cpp +++ b/src/postgres_utils.cpp @@ -1,4 +1,5 @@ #include "postgres_utils.hpp" + #include "storage/postgres_schema_entry.hpp" #include "storage/postgres_transaction.hpp" #include "postgres_type_oids.hpp" @@ -14,7 +15,7 @@ PGconn *PostgresUtils::PGConnect(const string &dsn, const string &attach_path) { // both PQStatus and PQerrorMessage check for nullptr if (PQstatus(conn) == CONNECTION_BAD) { char *msg_cstr = PQerrorMessage(conn); - std::string msg = msg_cstr != nullptr ? std::string(msg_cstr) : std::string(); + string msg = msg_cstr != nullptr ? string(msg_cstr) : string(); PQfinish(conn); throw IOException("Unable TODO:REMOVEME to connect to Postgres at \"%s\": %s", attach_path, msg); } @@ -539,7 +540,10 @@ PostgresVersion PostgresUtils::ExtractPostgresVersion(const string &version_str) } string PostgresUtils::QuotePostgresIdentifier(const string &text) { - return KeywordHelper::WriteOptionallyQuoted(text, '"', false); + if (!KeywordHelper::RequiresQuotes(text, false)) { + return text; + } + return PostgresUtils::WriteIdentifier(text); } string PostgresUtils::EscapeConnectionString(const string &input) { @@ -571,4 +575,31 @@ string PostgresUtils::ExtractConnectionOption(const KeyValueSecret &kv_secret, c return result; } +string PostgresUtils::EscapeQuotes(const string &text, char quote) { + string result; + for (auto c : text) { + if (c == quote) { + result += quote; + result += quote; + } else if (c == '\\') { + result += "\\\\"; + } else { + result += c; + } + } + return result; +} + +string PostgresUtils::WriteQuoted(const string &text, char quote) { + return string(1, quote) + EscapeQuotes(text, quote) + string(1, quote); +} + +string PostgresUtils::WriteLiteral(const string &literal) { + return WriteQuoted(literal, '\''); +} + +string PostgresUtils::WriteIdentifier(const string &identifier) { + return WriteQuoted(identifier, '"'); +} + } // namespace duckdb diff --git a/src/storage/postgres_catalog_set.cpp b/src/storage/postgres_catalog_set.cpp index a46aa241e..c9e7c8bb7 100644 --- a/src/storage/postgres_catalog_set.cpp +++ b/src/storage/postgres_catalog_set.cpp @@ -1,4 +1,5 @@ #include "storage/postgres_catalog_set.hpp" + #include "storage/postgres_transaction.hpp" #include "duckdb/parser/parsed_data/drop_info.hpp" #include "storage/postgres_schema_entry.hpp" @@ -66,9 +67,9 @@ void PostgresCatalogSet::DropEntry(PostgresTransaction &transaction, DropInfo &i drop_query += " IF EXISTS "; } if (!info.schema.empty()) { - drop_query += KeywordHelper::WriteQuoted(info.schema, '"') + "."; + drop_query += PostgresUtils::WriteIdentifier(info.schema) + "."; } - drop_query += KeywordHelper::WriteQuoted(info.name, '"'); + drop_query += PostgresUtils::WriteIdentifier(info.name); if (info.cascade) { drop_query += "CASCADE"; } diff --git a/src/storage/postgres_configure_pool.cpp b/src/storage/postgres_configure_pool.cpp index 912bcfa1a..9209dbe45 100644 --- a/src/storage/postgres_configure_pool.cpp +++ b/src/storage/postgres_configure_pool.cpp @@ -205,23 +205,23 @@ static void ConfigurePoolFunction(ClientContext &context, TableFunctionInput &in idx_t row_idx = 0; for (auto &pool : pools) { idx_t col_idx = 0; - output.SetValue(col_idx++, row_idx, Value(cat_names.at(row_idx))); - output.SetValue(col_idx++, row_idx, - Value(dbconnector::pool::AcquireModeHelpers::ToString(pool->GetAcquireMode()))); - output.SetValue(col_idx++, row_idx, Value::UBIGINT(pool->GetAvailableConnections())); - output.SetValue(col_idx++, row_idx, Value::UBIGINT(pool->GetMaxConnections())); - output.SetValue(col_idx++, row_idx, Value::UBIGINT(pool->GetWaitTimeoutMillis())); - output.SetValue(col_idx++, row_idx, Value::UBIGINT(pool->GetCacheHits())); - output.SetValue(col_idx++, row_idx, Value::UBIGINT(pool->GetCacheMisses())); - output.SetValue(col_idx++, row_idx, Value::UBIGINT(pool->GetTryFailures())); - output.SetValue(col_idx++, row_idx, Value::BOOLEAN(pool->IsThreadLocalCacheEnabled())); - output.SetValue(col_idx++, row_idx, Value::UBIGINT(pool->GetThreadLocalCacheHits())); - output.SetValue(col_idx++, row_idx, Value::UBIGINT(pool->GetThreadLocalCacheMisses())); - output.SetValue(col_idx++, row_idx, Value::UBIGINT(pool->GetMaxLifetimeMillis())); - output.SetValue(col_idx++, row_idx, Value::UBIGINT(pool->GetIdleTimeoutMillis())); - output.SetValue(col_idx++, row_idx, Value::BOOLEAN(pool->IsReaperRunning())); - output.SetValue(col_idx++, row_idx, Value::UBIGINT(pool->GetReaperPeriodMillis())); - output.SetValue(col_idx++, row_idx, Value(pool->GetHealthCheckQuery())); + output.data[col_idx++].SetValue(row_idx, Value(cat_names.at(row_idx))); + output.data[col_idx++].SetValue(row_idx, + Value(dbconnector::pool::AcquireModeHelpers::ToString(pool->GetAcquireMode()))); + output.data[col_idx++].SetValue(row_idx, Value::UBIGINT(pool->GetAvailableConnections())); + output.data[col_idx++].SetValue(row_idx, Value::UBIGINT(pool->GetMaxConnections())); + output.data[col_idx++].SetValue(row_idx, Value::UBIGINT(pool->GetWaitTimeoutMillis())); + output.data[col_idx++].SetValue(row_idx, Value::UBIGINT(pool->GetCacheHits())); + output.data[col_idx++].SetValue(row_idx, Value::UBIGINT(pool->GetCacheMisses())); + output.data[col_idx++].SetValue(row_idx, Value::UBIGINT(pool->GetTryFailures())); + output.data[col_idx++].SetValue(row_idx, Value::BOOLEAN(pool->IsThreadLocalCacheEnabled())); + output.data[col_idx++].SetValue(row_idx, Value::UBIGINT(pool->GetThreadLocalCacheHits())); + output.data[col_idx++].SetValue(row_idx, Value::UBIGINT(pool->GetThreadLocalCacheMisses())); + output.data[col_idx++].SetValue(row_idx, Value::UBIGINT(pool->GetMaxLifetimeMillis())); + output.data[col_idx++].SetValue(row_idx, Value::UBIGINT(pool->GetIdleTimeoutMillis())); + output.data[col_idx++].SetValue(row_idx, Value::BOOLEAN(pool->IsReaperRunning())); + output.data[col_idx++].SetValue(row_idx, Value::UBIGINT(pool->GetReaperPeriodMillis())); + output.data[col_idx++].SetValue(row_idx, Value(pool->GetHealthCheckQuery())); row_idx++; } diff --git a/src/storage/postgres_delete.cpp b/src/storage/postgres_delete.cpp index 7c9b02355..aab45b3d4 100644 --- a/src/storage/postgres_delete.cpp +++ b/src/storage/postgres_delete.cpp @@ -1,4 +1,5 @@ #include "storage/postgres_delete.hpp" + #include "storage/postgres_table_entry.hpp" #include "duckdb/planner/operator/logical_delete.hpp" #include "storage/postgres_catalog.hpp" @@ -20,7 +21,7 @@ PostgresDelete::PostgresDelete(PhysicalPlan &physical_plan, LogicalOperator &op, string GetDeleteSQL(const PostgresTableEntry &table, const string &ctid_list) { string result; result = "DELETE FROM "; - result += KeywordHelper::WriteQuoted(table.schema.name, '"') + "."; + result += PostgresUtils::WriteIdentifier(table.schema.name) + "."; result += PostgresUtils::QuotePostgresIdentifier(table.name); result += " WHERE ctid IN (" + ctid_list + ")"; return result; @@ -100,7 +101,7 @@ SourceResultType PostgresDelete::GetDataInternal(ExecutionContext &context, Data OperatorSourceInput &input) const { auto &insert_gstate = sink_state->Cast(); chunk.SetChildCardinality(1); - chunk.SetValue(0, 0, Value::BIGINT(insert_gstate.delete_count)); + chunk.data[0].SetValue(0, Value::BIGINT(insert_gstate.delete_count)); return SourceResultType::FINISHED; } diff --git a/src/storage/postgres_index_set.cpp b/src/storage/postgres_index_set.cpp index f18353803..fd8235818 100644 --- a/src/storage/postgres_index_set.cpp +++ b/src/storage/postgres_index_set.cpp @@ -1,11 +1,14 @@ #include "storage/postgres_index_set.hpp" -#include "storage/postgres_schema_entry.hpp" -#include "storage/postgres_transaction.hpp" + #include "duckdb/parser/expression/columnref_expression.hpp" #include "duckdb/parser/parsed_data/create_schema_info.hpp" -#include "storage/postgres_index_entry.hpp" #include "duckdb/parser/parsed_expression_iterator.hpp" +#include "postgres_utils.hpp" +#include "storage/postgres_index_entry.hpp" +#include "storage/postgres_schema_entry.hpp" +#include "storage/postgres_transaction.hpp" + namespace duckdb { PostgresIndexSet::PostgresIndexSet(PostgresSchemaEntry &schema, unique_ptr index_result_p) @@ -22,7 +25,7 @@ ORDER BY pg_namespace.oid; )"; string condition; if (!schema.empty()) { - condition += "WHERE pg_namespace.nspname=" + KeywordHelper::WriteQuoted(schema); + condition += "WHERE pg_namespace.nspname=" + PostgresUtils::WriteLiteral(schema); } return StringUtil::Replace(base_query, "${CONDITION}", condition); } diff --git a/src/storage/postgres_insert.cpp b/src/storage/postgres_insert.cpp index e754c0714..3bf1c0205 100644 --- a/src/storage/postgres_insert.cpp +++ b/src/storage/postgres_insert.cpp @@ -152,7 +152,7 @@ SourceResultType PostgresInsert::GetDataInternal(ExecutionContext &context, Data OperatorSourceInput &input) const { auto &insert_gstate = sink_state->Cast(); chunk.SetChildCardinality(1); - chunk.SetValue(0, 0, Value::BIGINT(insert_gstate.insert_count)); + chunk.data[0].SetValue(0, Value::BIGINT(insert_gstate.insert_count)); return SourceResultType::FINISHED; } diff --git a/src/storage/postgres_schema_set.cpp b/src/storage/postgres_schema_set.cpp index e6ef9db60..197d15c03 100644 --- a/src/storage/postgres_schema_set.cpp +++ b/src/storage/postgres_schema_set.cpp @@ -1,12 +1,15 @@ #include "storage/postgres_schema_set.hpp" + +#include "duckdb/parser/parsed_data/create_schema_info.hpp" +#include "duckdb/common/shared_ptr.hpp" + +#include "postgres_utils.hpp" #include "storage/postgres_index_set.hpp" #include "storage/postgres_table_set.hpp" #include "storage/postgres_type_set.hpp" #include "storage/postgres_transaction.hpp" -#include "duckdb/parser/parsed_data/create_schema_info.hpp" #include "storage/postgres_table_set.hpp" #include "storage/postgres_catalog.hpp" -#include "duckdb/common/shared_ptr.hpp" namespace duckdb { @@ -43,7 +46,7 @@ ORDER BY oid; )"; string condition; if (!schema.empty()) { - condition += "WHERE pg_namespace.nspname=" + KeywordHelper::WriteQuoted(schema); + condition += "WHERE pg_namespace.nspname=" + PostgresUtils::WriteLiteral(schema); } return StringUtil::Replace(base_query, "${CONDITION}", condition); } @@ -85,7 +88,7 @@ optional_ptr PostgresSchemaSet::CreateSchema(PostgresTransaction & if (info.on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT) { create_sql += " IF NOT EXISTS"; } - create_sql += KeywordHelper::WriteQuoted(info.schema, '"'); + create_sql += PostgresUtils::WriteIdentifier(info.schema); transaction.Query(create_sql); auto info_copy = info.Copy(); info.internal = PostgresSchemaEntry::SchemaIsInternal(info_copy->schema); diff --git a/src/storage/postgres_table_set.cpp b/src/storage/postgres_table_set.cpp index c3e903972..e99eec571 100644 --- a/src/storage/postgres_table_set.cpp +++ b/src/storage/postgres_table_set.cpp @@ -1,5 +1,5 @@ #include "storage/postgres_table_set.hpp" -#include "storage/postgres_transaction.hpp" + #include "duckdb/parser/parsed_data/create_table_info.hpp" #include "duckdb/parser/constraints/not_null_constraint.hpp" #include "duckdb/parser/constraints/unique_constraint.hpp" @@ -8,10 +8,13 @@ #include "duckdb/catalog/dependency_list.hpp" #include "duckdb/parser/parsed_data/create_table_info.hpp" #include "duckdb/parser/constraints/list.hpp" -#include "storage/postgres_schema_entry.hpp" #include "duckdb/parser/parser.hpp" #include "duckdb/common/string_util.hpp" + #include "postgres_conversion.hpp" +#include "postgres_utils.hpp" +#include "storage/postgres_transaction.hpp" +#include "storage/postgres_schema_entry.hpp" namespace duckdb { @@ -44,10 +47,10 @@ ORDER BY namespace_id, relname, attnum, constraint_id; )"; string condition; if (!schema.empty()) { - condition += "AND pg_namespace.nspname=" + KeywordHelper::WriteQuoted(schema); + condition += "AND pg_namespace.nspname=" + PostgresUtils::WriteLiteral(schema); } if (!table.empty()) { - condition += "AND relname=" + KeywordHelper::WriteQuoted(table); + condition += "AND relname=" + PostgresUtils::WriteLiteral(table); } return StringUtil::Replace(base_query, "${CONDITION}", condition); } @@ -243,7 +246,7 @@ string PostgresColumnsToSQL(const ColumnList &columns, const vector 0) { base += ", "; } - base += KeywordHelper::WriteQuoted(pk.columns[i], '"'); + base += PostgresUtils::WriteIdentifier(pk.columns[i]); } extra_constraints.push_back(base + ")"); } @@ -262,7 +265,7 @@ string PostgresColumnsToSQL(const ColumnList &columns, const vector 0) { ss << ", "; } - ss << KeywordHelper::WriteQuoted(column.Name(), '"') << " "; + ss << PostgresUtils::WriteIdentifier(column.Name()) << " "; ss << PostgresUtils::TypeToString(column.Type()); bool not_null = not_null_columns.find(column.Logical()) != not_null_columns.end(); bool is_single_key_pk = pk_columns.find(column.Logical()) != pk_columns.end(); @@ -308,10 +311,10 @@ string GetPostgresCreateTable(CreateTableInfo &info) { ss << "IF NOT EXISTS "; } if (!info.schema.empty()) { - ss << KeywordHelper::WriteQuoted(info.schema, '"'); + ss << PostgresUtils::WriteIdentifier(info.schema); ss << "."; } - ss << KeywordHelper::WriteQuoted(info.table, '"'); + ss << PostgresUtils::WriteIdentifier(info.table); ss << PostgresColumnsToSQL(info.columns, info.constraints); ss << ";"; return ss.str(); @@ -326,8 +329,8 @@ optional_ptr PostgresTableSet::CreateTable(PostgresTransaction &tr string PostgresTableSet::GetAlterTablePrefix(const string &name, optional_ptr entry) { string sql = "ALTER TABLE "; - sql += KeywordHelper::WriteQuoted(schema.name, '"') + "."; - sql += KeywordHelper::WriteQuoted(entry ? entry->name : name, '"'); + sql += PostgresUtils::WriteIdentifier(schema.name) + "."; + sql += PostgresUtils::WriteIdentifier(entry ? entry->name : name); return sql; } @@ -353,7 +356,7 @@ string PostgresTableSet::GetAlterTablePrefix(ClientContext &context, PostgresTra void PostgresTableSet::AlterTable(ClientContext &context, PostgresTransaction &transaction, RenameTableInfo &info) { string sql = GetAlterTablePrefix(context, transaction, info.name); sql += " RENAME TO "; - sql += KeywordHelper::WriteQuoted(info.new_table_name, '"'); + sql += PostgresUtils::WriteIdentifier(info.new_table_name); transaction.Query(sql); } @@ -362,9 +365,9 @@ void PostgresTableSet::AlterTable(ClientContext &context, PostgresTransaction &t string sql = GetAlterTablePrefix(info.name, entry); sql += " RENAME COLUMN "; string column_name = GetAlterTableColumnName(info.old_name, entry); - sql += KeywordHelper::WriteQuoted(column_name, '"'); + sql += PostgresUtils::WriteIdentifier(column_name); sql += " TO "; - sql += KeywordHelper::WriteQuoted(info.new_name, '"'); + sql += PostgresUtils::WriteIdentifier(info.new_name); transaction.Query(sql); } @@ -375,7 +378,7 @@ void PostgresTableSet::AlterTable(ClientContext &context, PostgresTransaction &t if (info.if_column_not_exists) { sql += "IF NOT EXISTS "; } - sql += KeywordHelper::WriteQuoted(info.new_column.Name(), '"'); + sql += PostgresUtils::WriteIdentifier(info.new_column.Name()); sql += " "; sql += info.new_column.Type().ToString(); @@ -402,7 +405,7 @@ void PostgresTableSet::AlterTable(ClientContext &context, PostgresTransaction &t sql += "IF EXISTS "; } string column_name = GetAlterTableColumnName(info.removed_column, entry); - sql += KeywordHelper::WriteQuoted(column_name, '"'); + sql += PostgresUtils::WriteIdentifier(column_name); transaction.Query(sql); } diff --git a/src/storage/postgres_type_set.cpp b/src/storage/postgres_type_set.cpp index 69f0b35fd..451355592 100644 --- a/src/storage/postgres_type_set.cpp +++ b/src/storage/postgres_type_set.cpp @@ -1,11 +1,14 @@ #include "storage/postgres_type_set.hpp" -#include "storage/postgres_transaction.hpp" + #include "duckdb/parser/parsed_data/create_type_info.hpp" -#include "storage/postgres_type_entry.hpp" #include "duckdb/parser/expression/constant_expression.hpp" -#include "storage/postgres_schema_entry.hpp" #include "duckdb/parser/parser.hpp" +#include "postgres_utils.hpp" +#include "storage/postgres_schema_entry.hpp" +#include "storage/postgres_type_entry.hpp" +#include "storage/postgres_transaction.hpp" + namespace duckdb { struct PGTypeInfo { @@ -39,7 +42,7 @@ ORDER BY n.oid, enumtypid, enumsortorder; )"; string condition; if (!schema.empty()) { - condition += "WHERE n.nspname=" + KeywordHelper::WriteQuoted(schema); + condition += "WHERE n.nspname=" + PostgresUtils::WriteLiteral(schema); } return StringUtil::Replace(base_query, "${CONDITION}", condition); } @@ -101,7 +104,7 @@ ORDER BY n.oid, t.oid, attrelid, attnum; )"; string condition; if (!schema.empty()) { - condition += "AND n.nspname=" + KeywordHelper::WriteQuoted(schema); + condition += "AND n.nspname=" + PostgresUtils::WriteLiteral(schema); } return StringUtil::Replace(base_query, "${CONDITION}", condition); } @@ -162,7 +165,7 @@ void PostgresTypeSet::LoadEntries(ClientContext &context, PostgresTransaction &t string GetCreateTypeSQL(CreateTypeInfo &info) { string sql = "CREATE TYPE "; - sql += KeywordHelper::WriteQuoted(info.name, '"'); + sql += PostgresUtils::WriteIdentifier(info.name); sql += " AS "; switch (info.type.id()) { case LogicalTypeId::ENUM: { @@ -173,7 +176,7 @@ string GetCreateTypeSQL(CreateTypeInfo &info) { sql += ", "; } auto enum_value = EnumType::GetString(info.type, i).GetString(); - sql += KeywordHelper::WriteQuoted(enum_value, '\''); + sql += PostgresUtils::WriteLiteral(enum_value); } sql += ")"; break; @@ -185,7 +188,7 @@ string GetCreateTypeSQL(CreateTypeInfo &info) { if (c > 0) { sql += ", "; } - sql += KeywordHelper::WriteQuoted(StructType::GetChildName(info.type, c), '"'); + sql += PostgresUtils::WriteIdentifier(StructType::GetChildName(info.type, c)); sql += " "; sql += PostgresUtils::TypeToString(StructType::GetChildType(info.type, c)); } diff --git a/src/storage/postgres_update.cpp b/src/storage/postgres_update.cpp index d6dd54469..95a3ad8de 100644 --- a/src/storage/postgres_update.cpp +++ b/src/storage/postgres_update.cpp @@ -1,4 +1,5 @@ #include "storage/postgres_update.hpp" + #include "storage/postgres_table_entry.hpp" #include "duckdb/planner/operator/logical_update.hpp" #include "storage/postgres_catalog.hpp" @@ -48,7 +49,7 @@ string CreateUpdateTable(const string &name, PostgresTableEntry &table, const ve for (idx_t i = 0; i < index.size(); i++) { auto &column_name = table.postgres_names[index[i].index]; auto &col = table.GetColumn(LogicalIndex(index[i].index)); - result += KeywordHelper::WriteQuoted(column_name, '"'); + result += PostgresUtils::WriteIdentifier(column_name); result += " "; result += PostgresUtils::TypeToString(col.GetType()); result += ", "; @@ -60,23 +61,23 @@ string CreateUpdateTable(const string &name, PostgresTableEntry &table, const ve string GetUpdateSQL(const string &name, PostgresTableEntry &table, const vector &index) { string result; result = "UPDATE "; - result += KeywordHelper::WriteQuoted(table.schema.name, '"') + "."; - result += KeywordHelper::WriteQuoted(table.name, '"'); + result += PostgresUtils::WriteIdentifier(table.schema.name) + "."; + result += PostgresUtils::WriteIdentifier(table.name); result += " SET "; for (idx_t i = 0; i < index.size(); i++) { if (i > 0) { result += ", "; } auto &column_name = table.postgres_names[index[i].index]; - result += KeywordHelper::WriteQuoted(column_name, '"'); + result += PostgresUtils::WriteIdentifier(column_name); result += " = "; - result += KeywordHelper::WriteQuoted(name, '"'); + result += PostgresUtils::WriteIdentifier(name); result += "."; - result += KeywordHelper::WriteQuoted(column_name, '"'); + result += PostgresUtils::WriteIdentifier(column_name); } result += " FROM " + PostgresUtils::QuotePostgresIdentifier(name); result += " WHERE "; - result += KeywordHelper::WriteQuoted(table.name, '"'); + result += PostgresUtils::WriteIdentifier(table.name); result += ".ctid=__page_id_string::TID"; return result; } @@ -181,7 +182,7 @@ SourceResultType PostgresUpdate::GetDataInternal(ExecutionContext &context, Data OperatorSourceInput &input) const { auto &insert_gstate = sink_state->Cast(); chunk.SetChildCardinality(1); - chunk.SetValue(0, 0, Value::BIGINT(insert_gstate.update_count)); + chunk.data[0].SetValue(0, Value::BIGINT(insert_gstate.update_count)); return SourceResultType::FINISHED; }