Problem/Motivation
One of the motivations for requiring SQLite 3.26 in Drupal 9 was the (improved) native UPSERT capability.
Proposed resolution
Let's use it :)
Remaining tasks
Review.
User interface changes
Nope.
API changes
Nope.
Data model changes
Nope.
Release notes snippet
Nope.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | interdiff-9.txt | 599 bytes | amateescu |
| #9 | 3159073-9.patch | 2.57 KB | amateescu |
Comments
Comment #2
amateescu commentedThe SQLite manual says that UPSERT follows the syntax established by PostgreSQL, so we just need to copy it over from
\Drupal\Core\Database\Driver\pgsql\Upsert::__toString().The small change in
pgsql\Upsert::__toString()was done to keep all 3 implementations as close as possible.Comment #3
amateescu commentedComment #4
andypostAny idea how to test effect? I used to try to measure changes of
drush si -ybut see no differenceComment #5
amateescu commentedWell.. the effect of this patch is limited because we are only using UPSERT queries in
Drupal\Core\Cache\DatabaseBackend, but once this is done we can start using it in a lot more places: #2547493: Add support for unique / primary key constraints composed of multiple fields for Upsert queriesComment #6
daffie commentedThe patch looks good to me, just one remark:
Could we add a comment with why this line is done this way and include a link to https://www.sqlite.org/lang_UPSERT.html.
We already have testing for upserts in Drupal/KernelTests/Core/Database/UpsertTest.
Comment #7
andypostHere's a patch with comment and link to official docs (having the link as @see makes it more visible for API site)
Comment #8
daffie commentedAll the code changes look good to me.
There already testing for upserts.
The patch has documentation.
For me it is RTBC.
Comment #9
amateescu commentedThanks for the review and updates, adding the same comment from #7 to the pgsql Upsert class, since we want to keep these methods in sync :)
Comment #10
catchThis is a direct conflict with #3107155: Raise SQLite version requirement to 3.26 in Drupal 9 - I think we need to explicitly close that issue as 'by design' if we go ahead here, so tagging.
Comment #11
ressaSince we are now around two weeks away from the first point release of Ubuntu 20.04 (20.04.1) it'll probably be all right to close that issue as 'by design'.
Certain assumptions were made in the other issue about Ubuntu, and I would just like to point out that when a new Ubuntu LTS is released, some cautious users will treat it as a RC-release, and not upgrade until the first point release is out, three to four months later.
Comment #12
andypost9.1 freeze in 4 weeks, so it always can be rolled back or BC shim could appear in contrib
Comment #15
daffie commentedThis issue is blocking #2755831: Make keyvalue and config stores for database faster by using upsert OR get() before set(). And that issue will result in a significant perfomance increasement when writing to the key_value tables. We are now using a merge query to write to the key_value tables and I would like to change that to an upsert query. Merge queries use first a select query to determine whether to use an insert query or an update query. Upsert queries do the same in one query.
Comment #16
daffie commentedOr the alternative issue #2547493: Add support for unique / primary key constraints composed of multiple fields for Upsert queries. We are not sure which we will close as a duplicate.
Comment #17
andypostHaving indexes (comment #116) could cause performance regressions so would be great to measure/profile install/rebuild
Comment #19
catch#3107155: Raise SQLite version requirement to 3.26 in Drupal 9 is now officially won't fix, so we can proceed here.
Committed dd164ae and pushed to 9.2.x. Thanks!
Comment #20
andypostIs this change backportable to 9.1.x? (patch applies)