Add support for unique / primary key constraints composed of multiple fields for Upsert querries, and start using it for config and key/value tables

Created on 7 August 2015, almost 9 years ago
Updated 29 August 2023, 10 months ago

Problem/Motivation

In #2542776: Add an Upsert class β†’ , we added an UPSERT query to the database system which only worked on tables with one unique index / primary key, composed of a single field. This limitation was imposed by the minimum SQLite version supported by Drupal at the time, which lacked proper support for UPSERT queries. In the meantime, SQLite added a real UPSERT in 3.24.

Proposed resolution

For Drupal 9.x we increased the minimum version of SQLite to 8.26 in #3107155: Discuss lowering SQLite version requirement from 3.26 to 3.22 in Drupal 9 β†’ , and one of the main motivations was the improved UPSERT capability, per #3107155-15: Discuss lowering SQLite version requirement from 3.26 to 3.22 in Drupal 9 β†’ .

Now that all three core database drivers support UPSERT queries on unique/primary key constraints composed of multiple fields, we should take advantage of it and replace core's usage of "Merge" queries where possible.

The benefit is that a Merge query is potentially composed of 3 separate queries (SELECT, INSERT and UPDATE), while UPSERTs can do the same thing (in most situations) in a single query.

Remaining tasks

Review.

User interface changes

Nope.

API changes

API addition, TBD.

Data model changes

Nope.

Release notes snippet

TBD.

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
DatabaseΒ  β†’

Last updated about 1 hour ago

  • Maintained by
  • πŸ‡³πŸ‡±Netherlands @daffie
Created by

πŸ‡·πŸ‡΄Romania amateescu

Live updates comments and jobs are added and updated live.
  • PostgreSQL

    Particularly affects sites running on the PostgreSQL database.

  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024