Skip to content

Support native UPSERTs & CrockroachDB#99

Merged
JohnMcLear merged 3 commits intoether:masterfrom
muxator:master
Mar 28, 2019
Merged

Support native UPSERTs & CrockroachDB#99
JohnMcLear merged 3 commits intoether:masterfrom
muxator:master

Conversation

@muxator
Copy link
Copy Markdown
Contributor

@muxator muxator commented Aug 28, 2017

Currently, when running on Postgres, UeberDB emulates UPSERTS operations on the key/value store via a pgsl function.

In 2016, with version 9.5, PostgreSQL gained the ability of natively performing UPSERTS on tables, via the SQL construct ON CONFLICT ... DO UPDATE.

CockroachDB, being externally modeled after PostgreSQL, also offers the same syntax.
As of version 1.x, CockroachDB does not support user defined functions.

This patch series aims to remove the use of the custom sql function ueberdb_insert_or_update() for performing upserts, and instead uses native statements when available.

The decision on using the upsert syntax or the sql function is taken based on feature detection, and not version sniffing.

The effects are:

  • no changes for PostgreSQL <= 9.4
  • performance improvements for PostgreSQL >= 9.5
  • support of CockroachDB

The code was tested with:

  • PostgreSQL 9.4 (falls back to the old behaviour)
  • PostgreSQL 9.5 (uses native statements)
  • CockroachDB 1.0.5 (works as above)

This is a preparatory commit to centralize the UPSERT statement before refactoring it.
Refactoring only: no functional changes.
Postgresql >= 9.5 and CockroachDB natively support UPSERT statements (ON CONFLICT ... DO UPDATE).

- when initializing the library, we run an EXPLAIN INSERT ... ON CONFLICT to check if the construct is supported
- if this succeeds, the UPSERT will be done done natively via ON CONFLICT ... DO UPDATE (Postgresql >= 9.5 and CockroachDB)
- if this fails, we will continue using the old behaviour of emulating UPSERT via ueberdb_insert_or_update() (Postgresql <= 9.4)

Among other things, this commit makes UeberDB compatible with CockroachDB
@muxator
Copy link
Copy Markdown
Contributor Author

muxator commented Oct 4, 2017

Hi @Pita, do you think this could be merged?
It this works out, the same change could be done to postgrespool_db.js, introduced in #97

@muxator
Copy link
Copy Markdown
Contributor Author

muxator commented Feb 15, 2018

Hi @Pita, do you think there could be any drawbacks merging this?

@JohnMcLear
Copy link
Copy Markdown
Member

@muxator are you willing to maintain this source for for at least 24 months from time of merge?

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

Successfully merging this pull request may close these issues.

2 participants