-
Notifications
You must be signed in to change notification settings - Fork 2.8k
remove hdb_views for inserts #3598
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
Conversation
|
Deploy preview for hasura-docs ready! Built with commit 9f0a5d0 |
b6acea3 to
ea97bfe
Compare
8a0563b to
ea0cab9
Compare
|
Review app for commit ea0cab9 deployed to Heroku: https://hge-ci-pull-3598.herokuapp.com |
ea0cab9 to
ef9d1ee
Compare
|
Review app for commit ef9d1ee deployed to Heroku: https://hge-ci-pull-3598.herokuapp.com |
ef9d1ee to
5fe1cce
Compare
|
Review app for commit 5fe1cce deployed to Heroku: https://hge-ci-pull-3598.herokuapp.com |
|
Tests are now passing 🎉 |
lexi-lambda
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally speaking, these changes look reasonable to me, but I’ll be honest: I don’t really understand them. Now, to be fair, I don’t think I really understood the old approach either, so that probably says less about the code and more about the abstract problem, but I think it would be great if some of the “why?” could make it into some comments somewhere.
The comment on insertPermsCheck seems very relevant, and indeed very helpful, but I think I’m missing a few pieces of context. Maybe just extending that comment slightly would be sufficient? I’ll leave it up to you.
|
@paf31 I looked through the changes, from what I understand, the generated insert statement is of this form: WITH
"<table>__mutation_result_alias" AS ( insert statement returning * ),
"<table>__inserted" AS ( SELECT .. ),
"<table>__checks" AS ( SELECT bool_and( .. WHEN check_expression ..) )
SELECT
"<table>__inserted".*
FROM
"<table>__inserted",
"<table>__checks"I experimented with a WITH
"<table>__mutation_result_alias" AS
( insert statement returning *, check_expression AS _check_expression_value ),
"<table>__inserted" AS ( SELECT .. ),
"<table>__checks" AS ( SELECT bool_and( .. WHEN _check_expression_value ..) )
SELECT
"<table>__inserted".*
FROM
"<table>__inserted",
"<table>__checks"The two statements that I used are as follows: Statement 1explain analyze with "address_mutation" as (
update
address a
set
location = 'blr'
where
id = 1 returning a.*
),
"address_check" as (
select
bool_and(
case
when (
exists (
select
1
from
"user" u
where
u.id = a.user_id
)
) THEN NULL
ELSE "hdb_catalog"."check_violation"()
end
)
from
"address_mutation" a
),
"address_return" as (
select
json_agg(a.*) as returning
from
"address_mutation" a
)
select
a.*
from
"address_return" a,
"address_check";Statement 2explain analyze with "address_mutation" as (
update
address a
set
location = 'blr'
where
id = 1 returning a.*,
(
exists (
select
1
from
"user" u
where
u.id = a.user_id
)
) as _check_condition
),
"address_check" as (
select
bool_and(
case
when (a._check_condition) THEN NULL
else "hdb_catalog"."check_violation"()
end
)
from
"address_mutation" a
),
"address_return" as (
select
json_agg(a.*) as returning
from
"address_mutation" a
)
select
a.*
from
"address_return" a,
"address_check";Regarding the During this refactor, I was also hoping that we would end up with simplified logic and fix some issues: Better error messagesIt would be good to have the object on which the constraint failed in the returned error message instead of the current "check constraint failed" (maybe something like "the following object '{"location":"blr"}' does not satisfy the check constraint"). This is particularly useful when you are inserting more than one objects or when inserting related data (through relationships). Different code paths based on relationships in selection setAssume the following schema: Let's say we issued a mutation such as this: mutation insert_address {
insert_address(objects: {location: "blr"}) {
affected_rows
returning {
user {
addresses {
id
location
}
}
}
}Now, ideally you would expect to generate SQL such as this: However, this doesn't work as expected (the address inserted as a part of this mutation will not be returned in the
So, whenever there are relationships in BEGIN
inserted rows <- INSERT INTO ...
WITH (inserted rows) AS "insert_result" SELECT .. from "insert_result"
COMMITThis also applies in case of deletes and updates. I was wondering if having the same code path would reduce some of the issues that we have been seeing with inserts (#3148, #3375, #3609). I have to admit, I'm not 100% familiar with the current insert mutations implementation so I do not know the implication of the changes that I'm proposing. @rakeshkky thoughts? |
|
@0x777 I'm not sure how I would inline the function body into the call site since it contains a I'm all for consolidating the different code paths. To be honest, I found the current way quite confusing, and I was trying to preserve the existing behavior. |
|
Review app for commit 4c79b84 deployed to Heroku: https://hge-ci-pull-3598.herokuapp.com |
|
Review app for commit acf0ce5 deployed to Heroku: https://hge-ci-pull-3598.herokuapp.com |
|
Review app for commit dd2cac2 deployed to Heroku: https://hge-ci-pull-3598.herokuapp.com |
|
Review app for commit 52f1070 deployed to Heroku: https://hge-ci-pull-3598.herokuapp.com |
52f1070 to
b563972
Compare
|
Review app for commit b563972 deployed to Heroku: https://hge-ci-pull-3598.herokuapp.com |
|
Review app for commit 6c4768b deployed to Heroku: https://hge-ci-pull-3598.herokuapp.com |
lexi-lambda
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These code changes LGTM, though I’m not sure I really understand what this code does well enough to thoroughly review it. @0x777 or @rakeshkky, could I ask one of you to review this as well?
More generally: I think it would be great to add some kind of high-level explanatory comment somewhere that explains the general idea. I don’t understand enough to know where it belongs or what it should say, though.
|
Review app for commit 9a8af83 deployed to Heroku: https://hge-ci-pull-3598.herokuapp.com |
|
Review app for commit e825e64 deployed to Heroku: https://hge-ci-pull-3598.herokuapp.com |
| :depth: 1 | ||
| :local: | ||
|
|
||
| From 29 to 28 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catalog version as per this PR is 30
Shouldn't we have 30 to 29 downgrade instructions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thanks. I forgot to change this when I merged master (which bumped from 29 to 30).
|
Review app for commit 9f0a5d0 deployed to Heroku: https://hge-ci-pull-3598.herokuapp.com |
shahidhk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0x777 and @lexi-lambda had already LGTM-ed
|
Review app https://hge-ci-pull-3598.herokuapp.com is deleted |
* WIP: Remove hdb_views for inserts * Show failing row in check constraint error * Revert "Show failing row in check constraint error" This reverts commit dd2cac2. * Use the better query plan * Simplify things * fix cli test * Update downgrading.rst * remove 1.1 asset for cli
Description
This is a precursor to #3533. It is an early WIP, but I'd like to put up this PR for review. In particular, I still need to:
err(text)function tohdb_viewsorhdb_catalogand create a migration for itAffected components
Related Issues
#3710
Solution and Design
Steps to test and verify
Limitations, known bugs & workarounds
Server checklist
Catalog upgrade
Does this PR change Hasura Catalog version?
Metadata
Does this PR add a new Metadata feature?
run_sqlauto manages the new metadata through schema diffing?run_sqlauto manages the definitions of metadata on renaming?export_metadata/replace_metadatasupports the new metadata added?GraphQL
Breaking changes
No Breaking changes
There are breaking changes:
Metadata API
Existing
querytypes:argspayload which is not backward compatibleJSONschemaGraphQL API
Schema Generation:
NamedTypeSchema Resolve:-
nullvalue for any input fieldsLogging
JSONschema has changedtypenames have changed