-
Notifications
You must be signed in to change notification settings - Fork 39
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
Initial RETURNING
implementation
#107
base: master
Are you sure you want to change the base?
Conversation
|
||
--Testcase 06: | ||
EXPLAIN (VERBOSE, COSTS OFF) | ||
UPDATE "type_STRING" SET col = '_' || substr(col, 2) RETURNING *; |
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.
You described "RETURNING have been introduced in SQLite 3.35.0", so we expect RETURNING clause will be pushed down to SQLite. Could you implement this point?
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.
I have begun in d339f8c , but removing a pushing down stopper is not enough, please see #107 (comment).
expected/17.0/extra/returning.out
Outdated
--Testcase 09: | ||
EXPLAIN (VERBOSE, COSTS OFF) | ||
DELETE FROM "type_STRING" RETURNING *; | ||
WARNING: DELETE ... RETURNING doesn't return values (not implemented) |
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.
WARNING: DELETE ... RETURNING doesn't return values (not implemented)
SQLite FDW already supported Direct Modification, I think RETURNING clause can be pushed down along with DELETE command. Could you implement this point?
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.
I am trying to implement universal (IUD) pushing down now.
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.
Implemented except to TupleDesc
processing after RETURNING
for some TCs, please verify by EXPLAIN
results.
|
||
--Testcase 11: | ||
EXPLAIN (VERBOSE, COSTS OFF) | ||
INSERT INTO "type_STRING"(col) VALUES ('string') ON CONFLICT DO NOTHING RETURNING *; |
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.
Currently, SQLiteFDW does not support ON CONFLICT DO NOTHING clause, I think you should separate this feature to another Pull Request or remove this its test and implementation.
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.
@lamdn1409 , why this is a problem? I thinks this is just INSERT
function tested and small internal detail or this touch some other code layers?
|
||
--Testcase 35: | ||
EXPLAIN (VERBOSE, COSTS OFF) | ||
INSERT INTO "type_STRING"(col) VALUES ('string') RETURNING *; |
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.
Similar to #107 (comment), INSERT ... RETURNING can be pushed down to SQLite.
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.
Please verify EXPLAIN
commands. is this enough in current TCs?
expected/17.0/extra/returning.out
Outdated
|
||
--Testcase 49: | ||
INSERT INTO "type_DATE"(col) VALUES ('2021.02.23') RETURNING col; | ||
ERROR: Failed to execute remote SQL |
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.
Could you add comment for the failed test cases below? What is your test purpose?
sql/17.0/extra/returning.sql
Outdated
--Testcase 46: | ||
INSERT INTO "type_BLOB"(col) VALUES (bytea('\xDEADBEEF')) RETURNING *; | ||
--Testcase 47: | ||
INSERT INTO typetest VALUES(1,'a', 'b', 'c','2017.11.06 12:34:56.789', '2017.11.06 12:34:56.789' ) RETURNING *; |
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.
Could you move this test case to the end of the test file (after testcase 62 and before testcase 47)?
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.
Done, please verify.
SELECT * FROM type_JSON; | ||
--Testcase 62 | ||
DELETE FROM type_JSON RETURNING *; | ||
|
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.
According to the specification https://www.sqlite.org/lang_returning.html, could you please add more test cases regarding RETURNING to verify the following points?
INSERT/DELETE/UPDATE combine RETURNING
- RETURNING expr
- RETURNING expr1, expr2,...
- RETURNING expr AS column-alias
- RETURNING expr1 AS column-alias1, expr2 AS column-alias2,...
- The RETURNING clause does not report any additional database changes caused by foreign key constraints or triggers.
- The output order for the RETURNING rows is arbitrary and is not necessarily related to the order in which the rows were processed internally.
- 07 items of Limitations And Caveats
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.
Will TC 60 ..100 enough?
sql/17.0/extra/returning.sql
Outdated
--Testcase 62 | ||
DELETE FROM type_JSON RETURNING *; | ||
|
||
--Testcase 47: |
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.
According to the test of postgres_fdw, please add test cases to verify the following points.
- RETURNING table, table.*
- RETURNING constant
- DELETE/UPDATE + WHERE + RETURNING
- DELETE/UPDATE + JOIN + WHERE + RETURNING
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.
RETURNING constant
DELETE/UPDATE + WHERE + RETURNING
Done. I'll prepare data for other tests.
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.
Could you add description about the feature to README.md file? |
/* | ||
* Add a RETURNING clause, if needed, to an INSERT/UPDATE/DELETE. | ||
*/ | ||
static void |
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.
Could you add definition for this function (prototype)?
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.
Please verify, @lamdn1409 !
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.
Please rename the function with the prefix sqlite_.
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.
Done, please confirm, @lamdn1409. I see this prefix.
Bitmapset *attrs_used = NULL; | ||
|
||
elog(DEBUG3, "sqlite_fdw : %s", __func__); | ||
if (trig_after_row) |
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.
Could you add test case to cover this condition?
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.
@lamdn1409 , I don't understand how can I test this trig_after_row
flag. What this is about in our context?
bms_make_singleton(0 - FirstLowInvalidHeapAttributeNumber); | ||
} | ||
|
||
if (withCheckOptionList != NIL) |
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.
Could you add test case to cover this condition?
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.
Is this about view after tested table https://www.postgresql.org/docs/17/sql-createview.html + https://www.postgresql.jp/document/16/html/fdw-callbacks.html#FDW-CALLBACKS-UPDATE ? Will this https://neon.tech/postgresql/postgresql-views/postgresql-views-with-check-option relevant TCs?
@mkgrgis Thanks for your contribution. I'm happy to work with you to support this feature. I have some review comments, could you please check them? |
Hello, @lamdn1409 ! Thanks for interesting review! Because this was mechanical edit by |
@lamdn1409, could you please help me to do a resume about code problem? |
Yes, no problems. Now there is short sentence after 04a9ef8 |
Look like there is something in |
@lamdn1409 , look like there is some problems with regressed and deleted |
@mkgrgis INSERT/DELETE/UPDATE ... RETURNING will be pushed down, so Direct Modification mechanism is activated , please check the routine PlanDirectModify, RETURNING clause should be deparsed at this step. |
Thanks, @lamdn1409 ! I am seeing some unchanged code, not unified with |
@lamdn1409 , I need a little help near https://github.com/mkgrgis/sqlite_fdw/blob/fc53e3639486d010f8988a371d2e70de5e4f1f8a/sqlite_fdw.c#L5105 I am confused how to integrate |
@mkgrgis I think result rows should be fetched in sqlite_execute_dml_stmt(). |
@lamdn1409 , I don't understand this place of data fetching. Now we have inside of if (rc != SQLITE_DONE)
{
sqlitefdw_report_error(ERROR, dmstate->stmt, dmstate->conn, NULL, rc);
} Hence, in case or |
@lamdn1409 , I have found |
|
Ok. I think this is main stream of our implementation.
Unfortunately I have unsuccessfully result now. |
@lamdn1409 , why there is no |
|
Yes, but discussed code fragment #107 (comment) treated all codes |
@mkgrgis I debugged your code, the error is reported as follows.
To debug, you need to build PostgreSQL 17.0 in debug mode. Use the following options. ./configure --prefix=<path_to_postgresql_build_folder> --enable-cassert --enable-debug CFLAGS="-ggdb -O0 -g3 -fno-omit-frame-pointer" For your reference, https://wiki.postgresql.org/wiki/Developer_FAQ#What_debugging_features_are_available.3F |
Thanks, @lamdn1409 ! Now I understand
as result of
I think this is very good information for "Contributing" in After #107 (comment)
I am still confused about place and possible content of missing |
@lamdn1409 , I have carefully read |
SQL
RETURNING
have been introduced in SQLite 3.35.0.I haven't noticed any special behaviour for
RETURNING
in SQLite not mapped to PostgreSQLRETURNING
behaviour.This PR made as mechanical edition according
postgres_fdw
code structures including naming conventions. This was enough for full ISO:SQLINSERT ... RETURNING
andUPDATE ... RETURNING
implementation. In case ofDELETE ... RETURNING
there are some problems and warning message was implemented.Implemented after #56