Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KIKIMR-20543: ddl+dml in query service #1444

Merged
merged 13 commits into from
Feb 26, 2024
Merged

Conversation

VPolka
Copy link
Collaborator

@VPolka VPolka commented Jan 31, 2024

Changelog entry

Add ability to use mixed ddl and dml queries in the ExecuteQuery handle in the query service

Changelog category

  • New feature

Additional information

@VPolka VPolka requested a review from a team as a code owner January 31, 2024 03:00
Copy link

github-actions bot commented Jan 31, 2024

2024-01-31 03:03:37 UTC Pre-commit check for 4800934 has started.
2024-01-31 03:03:40 UTC Build linux-x86_64-release-asan is running...
🔴 2024-01-31 03:41:32 UTC Build failed. see the build logs.
2024-01-31 03:41:47 UTC Tests are running...
🔴 2024-01-31 04:32:59 UTC Some tests failed, follow the links below.

Test history

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
12264 12143 0 97 4 20

Copy link

github-actions bot commented Jan 31, 2024

2024-01-31 03:03:38 UTC Pre-commit check for 4800934 has started.
2024-01-31 03:03:41 UTC Build linux-x86_64-relwithdebinfo is running...
🔴 2024-01-31 03:40:04 UTC Build failed. see the build logs.
2024-01-31 03:40:19 UTC Tests are running...
🔴 2024-01-31 04:19:32 UTC Some tests failed, follow the links below.

Test history

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
12583 12405 0 124 10 44

ydb/core/kqp/compile_service/kqp_compile_actor.cpp Outdated Show resolved Hide resolved
ydb/core/kqp/compile_service/kqp_compile_actor.cpp Outdated Show resolved Hide resolved
ydb/core/kqp/compile_service/kqp_compile_actor.cpp Outdated Show resolved Hide resolved
ydb/core/kqp/compile_service/kqp_compile_actor.cpp Outdated Show resolved Hide resolved
ydb/core/kqp/compile_service/kqp_compile_actor.cpp Outdated Show resolved Hide resolved
ydb/core/kqp/compile_service/kqp_compile_actor.cpp Outdated Show resolved Hide resolved
ydb/core/kqp/compile_service/kqp_compile_actor.cpp Outdated Show resolved Hide resolved
bool Insert(const TKqpCompileResult::TConstPtr& compileResult, bool isEnableAstCache) {
InsertQuery(compileResult);
bool Insert(const TKqpCompileResult::TConstPtr& compileResult, bool isEnableAstCache, bool isPerStatement) {
if (!isPerStatement) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will be with cache if we enable this new feature? They will not cache or they will be cached another way?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We won't save compilation result for statements by text, because all statements have the same query text, we will save their compilation results by ast

ydb/core/kqp/compile_service/kqp_compile_service.cpp Outdated Show resolved Hide resolved
ydb/core/kqp/compile_service/kqp_compile_service.cpp Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Feb 1, 2024

2024-02-01 12:04:38 UTC Pre-commit check for f547877 has started.
2024-02-01 12:04:40 UTC Build linux-x86_64-relwithdebinfo is running...
🟢 2024-02-01 12:41:33 UTC Build successful.
2024-02-01 12:41:49 UTC Tests are running...
🔴 2024-02-01 14:20:08 UTC Some tests failed, follow the links below.

Test history

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
60353 51048 0 2 9268 35

Copy link

github-actions bot commented Feb 1, 2024

2024-02-01 12:06:19 UTC Pre-commit check for f547877 has started.
2024-02-01 12:06:21 UTC Build linux-x86_64-release-asan is running...
🟢 2024-02-01 12:44:08 UTC Build successful.
2024-02-01 12:44:21 UTC Tests are running...
🔴 2024-02-01 14:28:04 UTC Some tests failed, follow the links below.

Test history

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
16037 15912 0 34 59 32

@@ -14,21 +14,23 @@ namespace NKikimr::NKqp::NPrivateEvents {

struct TEvCompileRequest: public TEventLocal<TEvCompileRequest, TKqpEvents::EvCompileRequest> {
TEvCompileRequest(const TIntrusiveConstPtr<NACLib::TUserToken>& userToken, const TMaybe<TString>& uid,
TMaybe<TKqpQueryId>&& query, bool keepInCache, TInstant deadline,
TMaybe<TKqpQueryId>&& query, bool keepInCache, bool canDivideIntoStatements, TInstant deadline,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Время завести builder? :)

ydb/core/kqp/common/compilation/events.h Show resolved Hide resolved
ydb/core/kqp/common/compilation/events.h Outdated Show resolved Hide resolved
ydb/core/kqp/compile_service/kqp_compile_actor.cpp Outdated Show resolved Hide resolved
ydb/core/kqp/compile_service/kqp_compile_actor.cpp Outdated Show resolved Hide resolved
ydb/core/kqp/compile_service/kqp_compile_actor.cpp Outdated Show resolved Hide resolved
ydb/core/kqp/compile_service/kqp_compile_actor.cpp Outdated Show resolved Hide resolved
YQL_ENSURE(queryAst.Ast);
YQL_ENSURE(queryAst.Ast->IsOk());
YQL_ENSURE(queryAst.Ast->Root);
auto compileResult = QueryCache.FindByAst(compileRequest.Query, *queryAst.Ast, compileRequest.KeepInCache);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я не очень знаком с FindByAst, а зачем нам тут и дескриптор запроса (compileRequest.Query) и сам AST?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Там же еще информация есть про базу данных, параметры, кластер. Нам же не достаточно только ast (как и текст) проверить?

ydb/core/kqp/host/kqp_translate.h Outdated Show resolved Hide resolved
ydb/core/protos/feature_flags.proto Outdated Show resolved Hide resolved
@@ -928,6 +945,7 @@ class TKqpSessionActor : public TActorBootstrapped<TKqpSessionActor> {

bool ExecutePhyTx(const TKqpPhyTxHolder::TConstPtr& tx, bool commit) {
if (tx) {
QueryState->PrepareStatementTransaction(tx->GetType());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот тут не очень очевидно как это работает в случае, если не per-statement.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Там внутри функции есть проверка на per-statement, иначе ничего не делается, но можно вынести на уровень повыше - сюда

TxCtx->EffectiveIsolationLevel = NKikimrKqp::ISOLATION_LEVEL_UNDEFINED;
break;
default:
Commit = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А вот тут не очень очевидно. Смотри, если мы говорим что у нас per-statement транзакция, то она может состоять из более чем одной PhyTx. Например:
UPSERT INTO ... SELECT * FROM ...

Вот тут будет две PhyTx, при этом это один стейтмент. Т.е. коммит должен идти не после каждой PhyTx, а в конце.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Проверила в логах, что коммитится действительно в конце стейтмента, но пока не понимаю, как бы это тестом покрыть

@@ -216,6 +216,35 @@ void PGParse(const TString& input, IPGParseEvents& events) {
}
}

List* PGGetStatements(const TString& input) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TArenaMemoryContext holds ownership of returned List*, so it's use after free

Please use PGParse method above

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed, could you please check it?

Copy link

github-actions bot commented Feb 15, 2024

2024-02-15 12:42:15 UTC Pre-commit check for 3d5e5f2 has started.
2024-02-15 12:42:18 UTC Build linux-x86_64-relwithdebinfo is running...
2024-02-15 13:00:44 UTC Check cancelled

Copy link

github-actions bot commented Feb 15, 2024

2024-02-15 12:42:41 UTC Pre-commit check for 3d5e5f2 has started.
2024-02-15 12:42:44 UTC Build linux-x86_64-release-asan is running...
2024-02-15 13:00:43 UTC Check cancelled

Copy link

github-actions bot commented Feb 15, 2024

2024-02-15 13:01:59 UTC Pre-commit check for 0235191 has started.
2024-02-15 13:02:00 UTC Build linux-x86_64-relwithdebinfo is running...
🟢 2024-02-15 13:24:34 UTC Build successful.
2024-02-15 13:24:50 UTC Tests are running...
🔴 2024-02-15 15:11:12 UTC Some tests failed, follow the links below.

Test history

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
67533 56482 0 3 10972 76

Copy link

github-actions bot commented Feb 15, 2024

2024-02-15 13:04:03 UTC Pre-commit check for 0235191 has started.
2024-02-15 13:04:05 UTC Build linux-x86_64-release-asan is running...
🟢 2024-02-15 13:28:47 UTC Build successful.
2024-02-15 13:28:59 UTC Tests are running...
🔴 2024-02-15 15:13:12 UTC Some tests failed, follow the links below.

Test history

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
14793 14580 0 21 140 52

@@ -107,6 +107,7 @@ namespace NSQLTranslation {
bool AssumeYdbOnClusterWithSlash;
TString DynamicClusterProvider;
TString FileAliasPrefix;
bool PerStatementExecution = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this is needed?

API is different - PGToYql/PGToYqlStatements, so an internal flag could be passed instead

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This param is needed in PG parser, because parsing with per statement mode or usual mode is inside in converter in method OnResult, converter is created with this settings, so because of this i put this param in settings, but it can be better to put this param in converter, not in setting

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move this setting to converter

Copy link

github-actions bot commented Feb 16, 2024

2024-02-16 18:58:36 UTC Pre-commit check for bb2c051 has started.
2024-02-16 18:58:39 UTC Build linux-x86_64-relwithdebinfo is running...
🟢 2024-02-16 19:38:43 UTC Build successful.
2024-02-16 19:38:58 UTC Tests are running...
🔴 2024-02-16 21:29:43 UTC Some tests failed, follow the links below.

Test history

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
67532 56509 0 2 10972 49

Copy link

github-actions bot commented Feb 16, 2024

2024-02-16 18:58:51 UTC Pre-commit check for bb2c051 has started.
2024-02-16 18:58:54 UTC Build linux-x86_64-release-asan is running...
🟢 2024-02-16 19:37:42 UTC Build successful.
2024-02-16 19:37:56 UTC Tests are running...
🔴 2024-02-16 21:20:37 UTC Some tests failed, follow the links below.

Test history

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
14773 14567 0 14 156 36

ydb/core/kqp/session_actor/kqp_session_actor.cpp Outdated Show resolved Hide resolved
ydb/core/kqp/session_actor/kqp_query_state.cpp Outdated Show resolved Hide resolved
ydb/core/kqp/session_actor/kqp_query_state.cpp Outdated Show resolved Hide resolved
ydb/core/kqp/session_actor/kqp_query_state.cpp Outdated Show resolved Hide resolved
@@ -143,16 +150,19 @@ std::unique_ptr<TEvKqp::TEvCompileRequest> TKqpQueryState::BuildCompileRequest(s
case NKikimrKqp::QUERY_ACTION_PREPARE:
query = TKqpQueryId(Cluster, Database, GetQuery(), settings, GetQueryParameterTypes());
keepInCache = query->IsSql();
perStatementResult = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there will be a difference between two ways of sql execution:

  1. ExecuteQuery with QUERY_ACTION_EXECUTE
  2. ExecuteQuery with QUERY_ACTION_PREPARE and then QUERY_ACTION_EXECUTE_PREPARED

I understand that we can't execute DDL and DML in one SQL without compiling queries after execution of previous statements (fresh tables are in DMLs). But do we realize what exactly will be different in usual DML queries?

ydb/core/kqp/session_actor/kqp_query_state.h Show resolved Hide resolved
ydb/library/yql/sql/sql.cpp Outdated Show resolved Hide resolved
TVector<NYql::TAstParseResult> result;
NYql::TIssues issues;
TTranslationSettings parsedSettings(settings);
google::protobuf::Arena arena;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same comment about arena

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case all protos that were constructed with this arena aren't returned outward, they are constructed and used in function SqlToAstStatements that called below

@@ -2660,6 +2660,75 @@ TNodePtr TSqlQuery::Build(const TSQLv1ParserAST& ast) {
WarnUnusedNodes();
return result;
}

TNodePtr TSqlQuery::Build(const std::vector<::NSQLv1Generated::TRule_sql_stmt_core>& statements) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that it's better to split query into statements here in parser? Did you check what we have in several statements query after pasing now? Maybe it is more convenient to split it into statements when we have TNodePtr pointing to root of the query?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have functionality with taking ast before compilation and checking it in the ast cache, and also we need PgAutoParams, that contains in AstResult class, so it was easier for me to do it in this way.

For query

$a = (SELECT * FROM TestDdl1);
UPSERT INTO TestDdl1 (Key, Value) VALUES (3, "Three");
SELECT * FROM $a;

ast without per-statements mode looks:

(
    (import aggregate_module "/lib/yql/aggregate.yql")
    (import window_module "/lib/yql/window.yql")
    (import core_module "/lib/yql/core.yql")
    (let subquerynode0 (block (
        (let x (Read! world (DataSource "kikimr" "db") (Key (table (String "/Root/TestDdl1"))) (Void) ()))
        (let world (Left! x))
        (let table0 (Right! x))
        (return (world (block (
            (let select (block ((let core table0) (let core (PersistableRepr (block ((let projectCoreType (TypeOf core)) (let core (SqlProject core ((SqlProjectStarItem projectCoreType "" (lambda (row) (block ((let res row) (return res)))) ())))) (return core))))) (return core))))
            (let select (RemoveSystemMembers select)) (return select))))))))
    (let world (Nth subquerynode0 0))
    (let subquery0 (Nth subquerynode0 1))
    (let world (block (
        (let values (PersistableRepr ((AsStruct ("Key" (Int32 "3")) ("Value" (String "Three"))))))
        (let world (block (
            (let sink (DataSink "kikimr" "db"))
            (let world (Write! world sink (Key (table (String "/Root/TestDdl1"))) values ((mode upsert))))
            (return world))))
        (return world))))
    (let world (block (
        (let output (block ((let select (block ((let core subquery0) (let core (PersistableRepr (block ((let projectCoreType (TypeOf core)) (let core (SqlProject core ((SqlProjectStarItem projectCoreType "" (lambda (row) (block ((let res row) (return res)))) ())))) (return core))))) (return core)))) (let select (RemoveSystemMembers select)) (return select))))
        (let world (block (
            (let result_sink (DataSink result))
            (let world (Write! world result_sink (Key) output ((type) (autoref))))
            (return (Commit! world result_sink)))))
        (return world))))
    (return world)
)

and with per-statements mode:

1)
(
    (import aggregate_module "/lib/yql/aggregate.yql")
    (import window_module "/lib/yql/window.yql")
    (import core_module "/lib/yql/core.yql")
    (let world (block (
        (let values (PersistableRepr ((AsStruct ("Key" (Int32 "3")) ("Value" (String "Three"))))))
        (let world (block (
            (let sink (DataSink "kikimr" "db"))
            (let world (Write! world sink (Key (table (String "/Root/TestDdl1"))) values ((mode upsert))))
            (return world))))
        (return world))))
    (return world)
)
2)
(
    (import aggregate_module "/lib/yql/aggregate.yql")
    (import window_module "/lib/yql/window.yql")
    (import core_module "/lib/yql/core.yql")
    (let subquerynode0 (block (
        (let x (Read! world (DataSource "kikimr" "db") (Key (table (String "/Root/TestDdl1"))) (Void) ()))
        (let world (Left! x))
        (let table0 (Right! x))
        (return (world (block (
            (let select (block ((let core table0) (let core (PersistableRepr (block ((let projectCoreType (TypeOf core)) (let core (SqlProject core ((SqlProjectStarItem projectCoreType "" (lambda (row) (block ((let res row) (return res)))) ())))) (return core))))) (return core))))
            (let select (RemoveSystemMembers select))
            (return select))))))))
    (let world (Nth subquerynode0 0))
    (let subquery0 (Nth subquerynode0 1))
    (let world (block (
        (let output (block ((let select (block ((let core subquery0) (let core (PersistableRepr (block ((let projectCoreType (TypeOf core)) (let core (SqlProject core ((SqlProjectStarItem projectCoreType "" (lambda (row) (block ((let res row) (return res)))) ())))) (return core))))) (return core)))) (let select (RemoveSystemMembers select)) (return select))))
        (let world (block (
            (let result_sink (DataSink result))
            (let world (Write! world result_sink (Key) output ((type) (autoref))))
            (return (Commit! world result_sink)))))
        (return world))))
    (return world)
)

I think that it is easier to build right ast in the beginning than rebuild this ast to several right asts with needed params, named nodes and so on, but of course we will have some problem that we need to support statement splitting in several parsers

spuchin
spuchin previously approved these changes Feb 19, 2024
Copy link

github-actions bot commented Feb 19, 2024

2024-02-19 13:30:18 UTC Pre-commit check for 5d87bbf has started.
2024-02-19 13:30:19 UTC Build linux-x86_64-relwithdebinfo is running...
🟢 2024-02-19 14:12:28 UTC Build successful.
2024-02-19 14:12:38 UTC Tests are running...
🔴 2024-02-19 16:04:02 UTC Some tests failed, follow the links below.

Test history

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
67574 56551 0 11 10979 33

Copy link

github-actions bot commented Feb 19, 2024

2024-02-19 13:37:53 UTC Pre-commit check for 5d87bbf has started.
2024-02-19 13:37:54 UTC Build linux-x86_64-release-asan is running...
🟢 2024-02-19 14:19:48 UTC Build successful.
2024-02-19 14:20:03 UTC Tests are running...
🔴 2024-02-19 16:08:16 UTC Some tests failed, follow the links below.

Test history

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
14781 14573 0 20 147 41

UgnineSirdis
UgnineSirdis previously approved these changes Feb 21, 2024
Copy link
Collaborator

@UgnineSirdis UgnineSirdis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks to me that we have discussed and resolved all important points

Copy link

github-actions bot commented Feb 26, 2024

2024-02-26 11:38:48 UTC Pre-commit check for 40dc1e5 has started.
2024-02-26 11:38:50 UTC Build linux-x86_64-relwithdebinfo is running...
🟢 2024-02-26 12:19:18 UTC Build successful.
2024-02-26 12:19:32 UTC Tests are running...
🔴 2024-02-26 14:10:07 UTC Some tests failed, follow the links below.

Test history

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
67945 57042 0 2 10883 18

Copy link

github-actions bot commented Feb 26, 2024

2024-02-26 11:38:50 UTC Pre-commit check for 40dc1e5 has started.
2024-02-26 11:38:52 UTC Build linux-x86_64-release-cmake14 is running...
🟢 2024-02-26 12:18:03 UTC Build successful.

Copy link

github-actions bot commented Feb 26, 2024

2024-02-26 11:39:41 UTC Pre-commit check for 40dc1e5 has started.
2024-02-26 11:39:44 UTC Build linux-x86_64-release-asan is running...
🟢 2024-02-26 12:17:28 UTC Build successful.
2024-02-26 12:17:42 UTC Tests are running...
🔴 2024-02-26 14:03:50 UTC Some tests failed, follow the links below.

Test history

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
14845 14718 0 16 86 25

@VPolka VPolka merged commit 4bf8208 into ydb-platform:main Feb 26, 2024
3 of 5 checks passed
@shnikd shnikd mentioned this pull request Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KIKIMR-20543: Возможность смешанного выполнения DDL+DML в QueryService
5 participants