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

[QueryService] Upserting and replacing rows with RETURNING raise INTERNAL ERROR #6699

Open
alex268 opened this issue Jul 15, 2024 · 5 comments
Assignees

Comments

@alex268
Copy link
Member

alex268 commented Jul 15, 2024

If I have a simple table like this

CREATE TABLE test1 (id Int32, v Text, PRIMARY KEY(id))

and execute next request via QueryService

UPSERT INTO test1 (id, v) VALUES (1, '321') RETURNING id, v;
REPLACE INTO test1 (id, v) VALUES (1, '111') RETURNING v, id;

I get an error

code = INTERNAL_ERROR(code=400030), issues = [
#1060 Execution (S_FATAL) 14:2 - 14:2: #1 contrib/ydb/core/kqp/opt/kqp_opt_kql.cpp:982  operator()(): requirement effectsMap[effect.Raw()] failed (S_FATAL),
#1060 Execution (S_FATAL) 14:2 - 14:2: #1 contrib/ydb/core/kqp/opt/kqp_opt_kql.cpp:982  operator()(): requirement effectsMap[effect.Raw()] failed (S_FATAL)
]

The same query via TableService works without problems.

@ssmike
Copy link
Collaborator

ssmike commented Jul 19, 2024

Query to TableService returns wrong column order. Fix attached.

@ssmike
Copy link
Collaborator

ssmike commented Jul 19, 2024

@alex268 Which branch are you using? Could you test against fresh master? Your query just works in ut

@alex268
Copy link
Member Author

alex268 commented Jul 19, 2024

I reproduce this error right now on the fresh YDB docker image. As I see this image was created July 19, but I am not sure that it was built from master branch. Original error was raised in this test and now it is still not working.
Information about docker image I used for tests:

        "Id": "sha256:be9c2e54403ef2c3f87de230b9c05a40c39c165490ef8f7b44678b1d09fcbfb0",
        "RepoTags": [
            "cr.yandex/yc/yandex-docker-local-ydb:trunk"
        ],
        "RepoDigests": [
            "cr.yandex/yc/yandex-docker-local-ydb@sha256:047286eec93a5204b30bf6cebe9e7b1338889bee8efc6b38113e66d270e49e42"
        ],
        "Parent": "",
        "Comment": "buildkit.dockerfile.v0",
        "Created": "2024-07-19T01:38:22.013840011Z",

@ssmike
Copy link
Collaborator

ssmike commented Jul 22, 2024

AST ut
(
(let $1 (DataSink '"kikimr" '"db"))
(let $2 '('id (Just (Int32 '1))))
(let $3 '('id 'v))
(let $4 '('('"input_columns" $3) '('"default_constraint_columns" '()) '('"generate_columns_if_insert" '())))
(let $5 (KiWriteTable! world $1 '"/Root/test1" (AsList (AsStruct $2 '('v (Just (Utf8 '"321"))))) 'upsert $4 $3))
15456 (let $6 '((KiReturningList! $5 $3) $3 '0))
15457 (let $7 '('v 'id))
15458 (let $8 (KiWriteTable! world $1 '"/Root/test1" (AsList (AsStruct $2 '('v (Just (Utf8 '"111"))))) 'replace $4 $7))
15459 (let $9 '((KiReturningList! $8 $7) $7 '0))
15460 (let $10 '('"db" '"/Root/test1" '"Upsert"))
15461 (let $11 '('"db" '"/Root/test1" '"Replace"))
15462 (let $12 '('('"mode" '"flush")))
(let $13 (KiExecDataQuery! world $1 (DataQueryBlocks (TKiDataQueryBlock '($6 $9) (KiEffects $5 $8) '($10 $11) '())) $12 (Void)))
(let $14 (DataSink '"result"))
(let $15 (Right! $13))
(let $16 (ResPull! (Left! $13) $14 (Key) (Nth $15 '0) '('('"columns" $3)) '"kikimr"))
(let $17 (ResPull! (Commit! $16 $14) $14 (Key) (Nth $15 '1) '('('"columns" $7)) '"kikimr"))
(return (Commit! (Commit! $17 $14) $1 $12))
)

AST docker
(
(let $1 (DataSink '"kikimr" '"db"))
(let $2 '('id (Just (Int32 '1))))
(let $3 '('id 'v))
(let $4 '('('"input_columns" $3) '('"default_constraint_columns" '()) '('"generate_columns_if_insert" '())))
(let $5 (KiWriteTable! world $1 '"/local/test1" (AsList (AsStruct $2 '('v (Just (Utf8 '"321"))))) 'upsert $4 $3))
(let $6 '('v 'id))
(let $7 (KiWriteTable! world $1 '"/local/test1" (AsList (AsStruct $2 '('v (Just (Utf8 '"111"))))) 'replace $4 $6))
(let $8 (TKiDataQueryBlock '('((KiReturningList! $5 $3) '() '0)) (KiEffects $5 $7) '('('"db" '"/local/test1" '"Upsert")) '()))
(let $9 (TKiDataQueryBlock '('((KiReturningList! $7 $6) '() '0)) (KiEffects) '('('"db" '"/local/test1" '"Replace")) '()))
(let $10 '('('"mode" '"flush")))
(let $11 (KiExecDataQuery! world $1 (DataQueryBlocks $8 $9) $10 (Void)))
(let $12 (DataSink '"result"))
(let $13 (Right! $11))
(let $14 (ResPull! (Left! $11) $12 (Key) (Nth $13 '0) '() '"kikimr"))
(let $15 (ResPull! (Commit! $14 $12) $12 (Key) (Nth $13 '1) '() '"kikimr"))
(return (Commit! (Commit! $15 $12) $1 $10))
)

@ssmike
Copy link
Collaborator

ssmike commented Jul 24, 2024

Should be resolved after #6980

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants