should be it

This commit is contained in:
2025-10-24 19:21:19 -05:00
parent a4b23fc57c
commit f09560c7b1
14047 changed files with 3161551 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
add_library_unity(test_catalog OBJECT test_catalog_version.cpp)
set(ALL_OBJECT_FILES
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:test_catalog>
PARENT_SCOPE)

View File

@@ -0,0 +1,99 @@
#include "catch.hpp"
#include "test_helpers.hpp"
#include "duckdb/main/extension/extension_loader.hpp"
#include "duckdb/main/extension_manager.hpp"
#include "duckdb.hpp"
using namespace duckdb;
void SomeTableFunc(duckdb::ClientContext &, duckdb::TableFunctionInput &, duckdb::DataChunk &) {
}
TEST_CASE("Test catalog versioning", "[catalog]") {
DBConfig config;
config.options.allow_unsigned_extensions = true;
DuckDB db(nullptr, &config);
Connection con1(db);
con1.context->RunFunctionInTransaction([&]() {
auto &catalog = Catalog::GetCatalog(*con1.context, "");
REQUIRE(catalog.GetCatalogVersion(*con1.context) == 0);
});
REQUIRE_NO_FAIL(con1.Query("CREATE TABLE foo as SELECT 42"));
con1.context->RunFunctionInTransaction([&]() {
auto &catalog = Catalog::GetCatalog(*con1.context, "");
REQUIRE(catalog.GetCatalogVersion(*con1.context) == 1);
});
{
REQUIRE_NOTHROW(con1.BeginTransaction());
REQUIRE_NO_FAIL(con1.Query("CREATE TABLE foo2 as SELECT 42"));
auto &catalog = Catalog::GetCatalog(*con1.context, "");
auto catalog_version_1 = catalog.GetCatalogVersion(*con1.context);
REQUIRE(catalog_version_1.GetIndex() > TRANSACTION_ID_START);
REQUIRE_NO_FAIL(con1.Query("CREATE TABLE foo3 as SELECT 42"));
auto catalog_version_2 = catalog.GetCatalogVersion(*con1.context);
REQUIRE(catalog_version_2.GetIndex() > catalog_version_1.GetIndex());
REQUIRE_NOTHROW(con1.Commit());
}
con1.context->RunFunctionInTransaction([&]() {
auto &catalog = Catalog::GetCatalog(*con1.context, "");
REQUIRE(catalog.GetCatalogVersion(*con1.context) == 2);
});
// The following should not increment the version
REQUIRE_NO_FAIL(con1.Query("CREATE TABLE IF NOT EXISTS foo3 as SELECT 42"));
con1.context->RunFunctionInTransaction([&]() {
auto &catalog = Catalog::GetCatalog(*con1.context, "");
REQUIRE(catalog.GetCatalogVersion(*con1.context) == 2);
});
REQUIRE_NO_FAIL(con1.Query("CREATE SCHEMA IF NOT EXISTS my_schema"));
con1.context->RunFunctionInTransaction([&]() {
auto &catalog = Catalog::GetCatalog(*con1.context, "");
REQUIRE(catalog.GetCatalogVersion(*con1.context) == 3);
});
// The following should not increment the version
REQUIRE_NO_FAIL(con1.Query("CREATE SCHEMA IF NOT EXISTS my_schema"));
con1.context->RunFunctionInTransaction([&]() {
auto &catalog = Catalog::GetCatalog(*con1.context, "");
REQUIRE(catalog.GetCatalogVersion(*con1.context) == 3);
});
// check catalog version of system catalog
con1.context->RunFunctionInTransaction([&]() {
auto &catalog = Catalog::GetCatalog(*con1.context, "system");
REQUIRE(catalog.GetCatalogVersion(*con1.context) == 1);
});
REQUIRE_NO_FAIL(con1.Query("ATTACH ':memory:' as foo"));
con1.context->RunFunctionInTransaction([&]() {
auto &catalog = Catalog::GetCatalog(*con1.context, "system");
REQUIRE(catalog.GetCatalogVersion(*con1.context) == 2);
});
// check new version of attached DB starts at 0
con1.context->RunFunctionInTransaction([&]() {
auto &catalog = Catalog::GetCatalog(*con1.context, "foo");
REQUIRE(catalog.GetCatalogVersion(*con1.context) == 0);
});
// system transactions do not register catalog version changes :/
duckdb::TableFunction tf("some_new_table_function", {}, SomeTableFunc);
ExtensionInfo extension_info {};
ExtensionActiveLoad load_info {*db.instance, extension_info, "test_catalog_extension"};
ExtensionLoader loader {load_info};
loader.RegisterFunction(tf);
con1.context->RunFunctionInTransaction([&]() {
auto &catalog = Catalog::GetCatalog(*con1.context, "system");
REQUIRE(catalog.GetCatalogVersion(*con1.context) == 2);
});
}