From 3d00dd9f97757ace1c705cce48cc60cbc592cd0e Mon Sep 17 00:00:00 2001 From: Zuleykha Pavlichenkova <zuleykha.pavlichenkova@gmail.com> Date: Thu, 4 Jul 2024 16:57:58 +0200 Subject: [PATCH 1/5] delete statement deletes a generated table reference --- src/include/statement_generator.hpp | 10 ++++++---- src/statement_generator.cpp | 8 ++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/include/statement_generator.hpp b/src/include/statement_generator.hpp index d699a4d..2f361bb 100644 --- a/src/include/statement_generator.hpp +++ b/src/include/statement_generator.hpp @@ -58,16 +58,18 @@ class StatementGenerator { unique_ptr<SQLStatement> GenerateStatement(StatementType type); // came from private private: - unique_ptr<MultiStatement> GenerateAttachUse(); - unique_ptr<SetStatement> GenerateSet(); unique_ptr<AttachStatement> GenerateAttach(); + unique_ptr<CreateStatement> GenerateCreate(); + unique_ptr<DeleteStatement> GenerateDelete(); unique_ptr<DetachStatement> GenerateDetach(); + unique_ptr<MultiStatement> GenerateAttachUse(); unique_ptr<SelectStatement> GenerateSelect(); - unique_ptr<CreateStatement> GenerateCreate(); + unique_ptr<SetStatement> GenerateSet(); + unique_ptr<QueryNode> GenerateQueryNode(); - unique_ptr<CreateInfo> GenerateCreateInfo(); unique_ptr<AttachInfo> GenerateAttachInfo(); + unique_ptr<CreateInfo> GenerateCreateInfo(); unique_ptr<DetachInfo> GenerateDetachInfo(); void GenerateCTEs(QueryNode &node); diff --git a/src/statement_generator.cpp b/src/statement_generator.cpp index 21a555d..1b72217 100644 --- a/src/statement_generator.cpp +++ b/src/statement_generator.cpp @@ -125,6 +125,8 @@ unique_ptr<SQLStatement> StatementGenerator::GenerateStatement(StatementType typ // generate USE statement case StatementType::SET_STATEMENT: return GenerateSet(); + case StatementType::DELETE_STATEMENT: + return GenerateDelete(); default: throw InternalException("Unsupported type"); } @@ -175,6 +177,12 @@ unique_ptr<MultiStatement> StatementGenerator::GenerateAttachUse() { return multi_statement; } +unique_ptr<DeleteStatement> StatementGenerator::GenerateDelete() { + auto delete_statement = make_uniq<DeleteStatement>(); + delete_statement->table = GenerateTableRef(); + return delete_statement; +} + //===--------------------------------------------------------------------===// // Generate Detach Info //===--------------------------------------------------------------------===// From f10099422368670adc225a3b91a232ea8f6c93f4 Mon Sep 17 00:00:00 2001 From: Zuleykha Pavlichenkova <zuleykha.pavlichenkova@gmail.com> Date: Thu, 4 Jul 2024 17:54:28 +0200 Subject: [PATCH 2/5] add missing condition to generate delete statement --- src/statement_generator.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/statement_generator.cpp b/src/statement_generator.cpp index 1b72217..5e4c547 100644 --- a/src/statement_generator.cpp +++ b/src/statement_generator.cpp @@ -109,6 +109,9 @@ unique_ptr<SQLStatement> StatementGenerator::GenerateStatement() { if (RandomPercentage(30)) { return GenerateStatement(StatementType::SET_STATEMENT); } + if (RandomPercentage(20)) { + return GenerateStatement(StatementType::DELETE_STATEMENT); + } return GenerateStatement(StatementType::CREATE_STATEMENT); } From e071f3ba69399be659e7ee0cbd3c05010145e121 Mon Sep 17 00:00:00 2001 From: Zuleykha Pavlichenkova <zuleykha.pavlichenkova@gmail.com> Date: Tue, 9 Jul 2024 12:00:12 +0200 Subject: [PATCH 3/5] add Delete statement --- src/statement_generator.cpp | 50 ++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/src/statement_generator.cpp b/src/statement_generator.cpp index 5e4c547..5540cae 100644 --- a/src/statement_generator.cpp +++ b/src/statement_generator.cpp @@ -93,23 +93,23 @@ std::shared_ptr<GeneratorContext> StatementGenerator::GetDatabaseState(ClientCon } unique_ptr<SQLStatement> StatementGenerator::GenerateStatement() { - if (RandomPercentage(80)) { - return GenerateStatement(StatementType::SELECT_STATEMENT); - } - if (RandomPercentage(40)) { - if (RandomPercentage(50)) { - // We call this directly so we have a higher chance to fuzz persistent databases - return GenerateAttachUse(); - } - return GenerateStatement(StatementType::ATTACH_STATEMENT); - } - if (RandomPercentage(60)) { - return GenerateStatement(StatementType::DETACH_STATEMENT); - } - if (RandomPercentage(30)) { - return GenerateStatement(StatementType::SET_STATEMENT); - } - if (RandomPercentage(20)) { + // if (RandomPercentage(80)) { + // return GenerateStatement(StatementType::SELECT_STATEMENT); + // } + // if (RandomPercentage(40)) { + // if (RandomPercentage(50)) { + // // We call this directly so we have a higher chance to fuzz persistent databases + // return GenerateAttachUse(); + // } + // return GenerateStatement(StatementType::ATTACH_STATEMENT); + // } + // if (RandomPercentage(60)) { + // return GenerateStatement(StatementType::DETACH_STATEMENT); + // } + // if (RandomPercentage(30)) { + // return GenerateStatement(StatementType::SET_STATEMENT); + // } + if (RandomPercentage(40)) { //20 return GenerateStatement(StatementType::DELETE_STATEMENT); } return GenerateStatement(StatementType::CREATE_STATEMENT); @@ -182,7 +182,21 @@ unique_ptr<MultiStatement> StatementGenerator::GenerateAttachUse() { unique_ptr<DeleteStatement> StatementGenerator::GenerateDelete() { auto delete_statement = make_uniq<DeleteStatement>(); - delete_statement->table = GenerateTableRef(); + auto state = GetDatabaseState(context); + if (!generator_context->tables_and_views.empty()) { + auto &entry_ref = Choose(generator_context->tables_and_views); + auto &entry = entry_ref.get(); + if (entry.type == CatalogType::TABLE_ENTRY) { + auto result = make_uniq<BaseTableRef>(); + result->table_name = entry.name; + delete_statement->table = std::move(result); + } else { + delete_statement->table = GenerateTableRef(); + } + } else { + delete_statement->table = GenerateTableRef(); + } + return delete_statement; } From 5b0fe8b84f556f550fc8eba98f7cfe9c096a3653 Mon Sep 17 00:00:00 2001 From: Zuleykha Pavlichenkova <zuleykha.pavlichenkova@gmail.com> Date: Tue, 9 Jul 2024 12:15:29 +0200 Subject: [PATCH 4/5] missed to uncomment lines fix indentation added two more jobs to build and deploy main version Update .github/workflows/MainDistributionPipeline.yml Co-authored-by: Carlo Piovesan <piovesan.carlo@gmail.com> --- .../workflows/MainDistributionPipeline.yml | 10 +++++- src/statement_generator.cpp | 36 +++++++++---------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/.github/workflows/MainDistributionPipeline.yml b/.github/workflows/MainDistributionPipeline.yml index 1e26fae..39f9ac8 100644 --- a/.github/workflows/MainDistributionPipeline.yml +++ b/.github/workflows/MainDistributionPipeline.yml @@ -29,4 +29,12 @@ jobs: duckdb_version: v1.0.0 extension_name: sqlsmith exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads;windows_amd64_rtools' - deploy_latest: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' }} \ No newline at end of file + deploy_latest: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' }} + + duckdb-main-build: + name: Build extension binaries + uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@v1.0.0 + with: + duckdb_version: main + extension_name: sqlsmith + exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads;windows_amd64_rtools' diff --git a/src/statement_generator.cpp b/src/statement_generator.cpp index 5540cae..4e20391 100644 --- a/src/statement_generator.cpp +++ b/src/statement_generator.cpp @@ -93,22 +93,22 @@ std::shared_ptr<GeneratorContext> StatementGenerator::GetDatabaseState(ClientCon } unique_ptr<SQLStatement> StatementGenerator::GenerateStatement() { - // if (RandomPercentage(80)) { - // return GenerateStatement(StatementType::SELECT_STATEMENT); - // } - // if (RandomPercentage(40)) { - // if (RandomPercentage(50)) { - // // We call this directly so we have a higher chance to fuzz persistent databases - // return GenerateAttachUse(); - // } - // return GenerateStatement(StatementType::ATTACH_STATEMENT); - // } - // if (RandomPercentage(60)) { - // return GenerateStatement(StatementType::DETACH_STATEMENT); - // } - // if (RandomPercentage(30)) { - // return GenerateStatement(StatementType::SET_STATEMENT); - // } + if (RandomPercentage(80)) { + return GenerateStatement(StatementType::SELECT_STATEMENT); + } + if (RandomPercentage(40)) { + if (RandomPercentage(50)) { + // We call this directly so we have a higher chance to fuzz persistent databases + return GenerateAttachUse(); + } + return GenerateStatement(StatementType::ATTACH_STATEMENT); + } + if (RandomPercentage(60)) { + return GenerateStatement(StatementType::DETACH_STATEMENT); + } + if (RandomPercentage(30)) { + return GenerateStatement(StatementType::SET_STATEMENT); + } if (RandomPercentage(40)) { //20 return GenerateStatement(StatementType::DELETE_STATEMENT); } @@ -187,11 +187,11 @@ unique_ptr<DeleteStatement> StatementGenerator::GenerateDelete() { auto &entry_ref = Choose(generator_context->tables_and_views); auto &entry = entry_ref.get(); if (entry.type == CatalogType::TABLE_ENTRY) { - auto result = make_uniq<BaseTableRef>(); + auto result = make_uniq<BaseTableRef>(); result->table_name = entry.name; delete_statement->table = std::move(result); } else { - delete_statement->table = GenerateTableRef(); + delete_statement->table = GenerateTableRef(); } } else { delete_statement->table = GenerateTableRef(); From 8e676a2c6bd0e0dce5d17740dc412d03f5027932 Mon Sep 17 00:00:00 2001 From: Zuleykha Pavlichenkova <zuleykha.pavlichenkova@gmail.com> Date: Mon, 15 Jul 2024 13:04:20 +0200 Subject: [PATCH 5/5] delete excluded architectures --- .github/workflows/MainDistributionPipeline.yml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/.github/workflows/MainDistributionPipeline.yml b/.github/workflows/MainDistributionPipeline.yml index 39f9ac8..ed98c23 100644 --- a/.github/workflows/MainDistributionPipeline.yml +++ b/.github/workflows/MainDistributionPipeline.yml @@ -16,25 +16,15 @@ jobs: name: Build extension binaries uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@v1.0.0 with: - duckdb_version: v1.0.0 + duckdb_version: main extension_name: sqlsmith - exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads;windows_amd64_rtools' duckdb-stable-deploy: name: Deploy extension binaries needs: duckdb-stable-build uses: duckdb/extension-ci-tools/.github/workflows/_extension_deploy.yml@v1.0.0 secrets: inherit - with: - duckdb_version: v1.0.0 - extension_name: sqlsmith - exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads;windows_amd64_rtools' - deploy_latest: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' }} - - duckdb-main-build: - name: Build extension binaries - uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@v1.0.0 with: duckdb_version: main extension_name: sqlsmith - exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads;windows_amd64_rtools' + deploy_latest: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' }}