Problem/Motivation

  • We currently store several serialized data structures in the database, such as {config}.data, {cache_*}.data, the Layout Builder data of per-entity layouts, and plenty others. Many of these would benefit from being serialized as JSON instead of PHP. #3046696: Move from serialized columns to JSON encoded data wherever possible, or use allowed_classes includes some discussion about this.
  • Nearly all modern relational databases now support a json datatype and corresponding JSON parsing functions that can be used during querying. If we could rely on this within our database system, then in following Drupal 10 minor releases we could add the APIs for efficiently querying these structures. For example, Drupal\Core\Config\Entity\Query\Query could be reimplemented as native queries by the database rather than its current implementation of in-memory PHP filtering only partially optimizable with a keystore. Or, Layout Builder could provide a way to query entities by aspects of its layout.

Proposed resolution

Require json support for all database drivers, both for the ones in core and for contrib/custom. This would mean:

  • DONE in Drupal 9 already: For MySQL require at least 5.7.8; and for MariaDB require at least 10.2.7. See #3107113: [policy] Decide on MySQL/MariaDB/Percona Server version support status for Drupal 9.
  • DONE in Drupal 9 already: For PostgreSQL require at least 9.4. See #3106077: [policy] Decide on PostgreSQL 9.x/10.x support status.
  • For SQLite, version isn't an issue, but we'd have to require that it be compiled with the json1 extension. This is the default since 3.24, and Drupal 9 requires 3.26, but it would still be possible for it to be compiled without the extension, so we'd need the ability to check for it.
  • In contrib/custom space:
    • Microsoft SQL Server supports JSON beginning with version 2016. Mainstream support of earlier SQL Server versions has ended, but version 2012 still has extended support until 2022 and version 2014 still has extended support until 2024.
    • Oracle supports JSON beginning with version 12. Extended support of version 11 ends in Dec. 2020.
    • Any other SQL databases that we care about?

Remaining tasks

  • Decide if it's acceptable to require these minimum database versions.
  • Decide if it's acceptable to disallow SQLite usage for people whose SQLite is compiled without the json1 extension.

Release note snippet

All databases must support JSON from Drupal 10.0.0 onwards. While all of the databases required by Drupal 9 already support JSON, sqlite will always need to be compiled with the json1 extension (already the default).

Comments

effulgentsia created an issue. See original summary.

effulgentsia’s picture

Issue summary: View changes
effulgentsia’s picture

Issue summary: View changes
andypost’s picture

Interesting point about official PHP docker images, they based on debian:buster and alpine, so both should be fine for sqlite

daffie’s picture

The question that I have is: How easy is it for Windows and Mac users to get SQLite on their systems with the json1 extension? (and also with the DSQLITE_MAX_VARIABLE_NUMBER setting being higher then/equal 250000?)
Does anybody have any idea how many people on Windows and Mac use SQLite as a database for Drupal to test it out?

daffie’s picture

effulgentsia’s picture

How easy is it for Windows and Mac users to get SQLite on their systems with the json1 extension?

Since D9 requires PHP 7.3, the first part is getting at least PHP 7.3. On Mac Mojave, the shipped PHP version is 7.1. One way to get PHP 7.3 or 7.4 is to install MAMP 5.6. Via that, both the PHP 7.3 and 7.4 builds include SQLite with the json1 extension. Another way to get PHP 7.3 or 7.4 is with Homebrew. Via that, both the PHP 7.3 and 7.4 builds also include SQLite with the json1 extension. On Mac Catalina, the shipped PHP version is 7.3, and it also includes SQLite with the json1 extension.

I don't know about Windows.

and also with the DSQLITE_MAX_VARIABLE_NUMBER setting being higher then/equal 250000?

I don't know. I'll try to find out though.

daffie’s picture

I have asked the same question on #3107155-11: Raise SQLite version requirement to 3.26 in Drupal 9 and @andypost answered with

I bet windows will use WSL in d9 era, so some Linux-distro, on MacOS this limit is higher iirc
effulgentsia’s picture

Looks like it was SQLite 3.24 that started enabling json support by default. Note, that's only by default if you're using their autoconf script to configure the compilation. Now I'm more curious about Ubuntu 18.04, which ships with 3.22, but I thought had it with json support, which would imply they compiled it with non-default arguments. I'll see if I can confirm that.

effulgentsia’s picture

Found it: https://git.launchpad.net/ubuntu/+source/sqlite3/tree/debian/rules?h=ubu.... I think this means that 3.22+ on Ubuntu and 3.24+ elsewhere is likely to have json support.

mglaman’s picture

I'd love to have JSON support in all database drivers, but I'd say a lot of my day to day involves Drupal on SQLite for local development and contrib development. It sounds like #7 shows it is (most likely) a non problem on macOS?

effulgentsia’s picture

And here's where it was added to PHP 7.3 prior to becoming unbundled (and therefore using however it was compiled on the system) in PHP 7.4.

So the summary is, SQLite json support is ON by default in all of:

  • PHP 7.3, regardless of system
  • PHP 7.4 if the SQLite on the system is 3.24 or higher
  • PHP 7.4 if the SQLite on the system is the 3.22 that's shipped with Ubuntu 18.04
  • Possibly others too, though I don't know if we care about any others, since I think all other systems that we care about for D9, including MacOS Mojave and Catalina, come with SQLite 3.24 or higher.
gábor hojtsy’s picture

catch’s picture

We're already planning to increase requirements for MySQL, postgres and sqlite to version that support JSON, and the required versions for contrib drivers don't seem onerous.

The only question for me is whether it's worth officially requiring support in the database drivers before we have support for it in Drupal. i.e. we'd need to add JSON support to the database layer, and then we'd need an implementation in core. We only really need to require JSON once we have a non-optional core implementation. I guess there's an argument that it's better to add the requirement prior to a major version rather than during if we expect to have an implementation added prior to 10.x though.

andypost’s picture

effulgentsia’s picture

Status: Active » Reviewed & tested by the community
Related issues: +#3118766: Require 12.1 as the minimum Oracle version for the Drupal 9 version of this driver

The feedback in #3113753-2: Can the SQL Server minimum be raised to 2016 for Drupal 9? was +1.

I just now opened #3118766: Require 12.1 as the minimum Oracle version for the Drupal 9 version of this driver.

I think that makes this decision RTBC, but we still need to figure out how to best communicate it (probably a change record, maybe also a release note mention?, maybe a handbook page?) so that other contrib/custom db drivers out there know about this.

catch’s picture

https://www.drupal.org/docs/9/how-drupal-9-is-made-and-what-is-included/... is the requirements page, it could be a footnote there maybe?

Both a CR and release not seems sensible for this one.

alexpott’s picture

A slightly sad thing is that postgres doesn't support generated columns until version 12 (only just released) and SQLite in 3.31.0 (only just released too). MySQL supports this since 5.7. This is important because it we want to have indexes on anything in the json this would make that possible. Considering configuration - that'd allow us to remove the awfulness of storing configuration lookup keys in state. Here's an article that explains what generated columns are and why they are important... https://www.percona.com/blog/2016/03/07/json-document-fast-lookup-with-m...

andypost’s picture

Btw sqlite 3.31 adds uuid function, so follow up for uuid fields needs to be filed

effulgentsia’s picture

Re #19, PostgreSQL supports jsonb indexing (since 9.5) and SQLite supports expression indexing (since 3.9). Is that not enough for most json querying use cases, including config?

alexpott’s picture

@effulgentsia that does look interesting - that'd be great for config. Shame MySQL doesn't offer an equivalent - apart from the generated columns thing. Will be fun to add sort for json indexes in an db agnostic way... the things you point to make it look easier for SQLite and Postgres.

catch’s picture

We should add #19 to whatever the 10.x database requirements issue is (I think there already is one, or at least a meta with a placeholder).

andypost’s picture

Looks #21-22 are more about related

catch’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs release note, +Needs change record

So we still need a release note and change record here, but also this seems a bit late now we're already close to RC - we should really have documented it when the decision was made.

andypost’s picture

Version: 9.0.x-dev » 9.2.x-dev

As it goes to 10.0 it can bet on php-sqlite will linked to system library

catch’s picture

Title: [policy] Decide whether to require json support for all database drivers for Drupal 9? » [policy] Decide whether to require json support for all database drivers for Drupal 10
Category: Task » Plan

Updating the issue summary. We should try to reach a decision here sooner than later so we can bump Drupal 10's database requirements as soon as it opens.

daffie’s picture

+1

For >99% of the Drupal sites there will be a free performance increasement. I am not sure how much that increasement will be. For the <1% of the sites that run Microsoft SQL Server lower then version 16 or SQLite with PHP 7.3, they will not get support for Drupal 10. That will only be a handful of sites. Also AFAIK PHP 7.3 will not be supported on Drupal 10. For me this is an easy choose. I fully support having json support as a requirement for all databases in Drupal 10.

catch’s picture

Tried a bit of an issue summary update.

mradcliffe’s picture

Just a quick note while I have some time and thinking about this.

We don't need any abstraction for simply storing JSON since it's text. However we will need an abstraction layer for querying or parsing JSON data structures in SQL. A mechanism for accessing nested properties in Condition or Select fields needs to be worked on. I don't think that should block requiring drivers to implement a json (or extended json) data type. Giving the ability to store JSON is a big DX win in my opinion.

moshe weitzman’s picture

+1 from me as well. Whats left before RTBC?

gábor hojtsy’s picture

Status: Needs review » Needs work

As per the tags a release note snippet for the issue summary and a change record for people to have time to prepare would be needed :)

gábor hojtsy’s picture

BTW looking at the proposed resolution to write up the change record, it seems like the proposed MySQL/MariaDB and PostgreSQL requirements are already in place in Drupal 9. So which database requirements are actually affected by this proposal?

mglaman’s picture

The main problem would be SQLite. Anything else are in contrib drivers

From the issue summary:

For SQLite, version isn't an issue, but we'd have to require that it be compiled with the json1 extension. This isn't the default, but (some? all?) Linux distributions include it in their build of it. For example, Ubuntu does. From PHP 7.4 sqlite uses the library on the system. Drupal 10 will require at least PHP 8.0

https://www.sqlite.org/json1.html

gábor hojtsy’s picture

Issue summary: View changes

Updating the issue summary to reflect the MySQL and PostgreSQL status as done in Drupal 9 already.

effulgentsia’s picture

Per #9, SQLite started compiling in the json1 extension by default starting with 3.24. Drupal 9 already requires 3.26.

This is a policy issue, but in terms of implementation, I think we'll want to add something to Drupal\Core\Database\Install\Tasks, either concrete or abstract for drivers to implement, to test for json support. That would catch the case of a non-default compilation of SQLite that's missing the json1 extension, or contrib drivers that are missing the required capabilities.

catch’s picture

Issue summary: View changes

Updated the issue summary based on #37.

daffie’s picture

Issue summary: View changes

Nitpick IS update.

+1 from me for adding the json1 extension as required for SQLite in D10.

daffie’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs change record

Created the followup issue for adding the json1 extension requirements test in Drupal 10 for SQLite. See: #3192487: Warn about upcoming JSON database support requirement in Drupal 9.
Created the CR.
The issue is now for me RTBC.

catch’s picture

Issue summary: View changes
catch’s picture

Issue tags: -Needs release note

Added a release notes snippet.

mradcliffe’s picture

I added versions for Oracle and SQL Server to the change record.

I think eventually this would impact usages of Redis and Memcache. Does it make sense to mention that in this change record?

catch’s picture

@mradcliffe if we implement/require JSON support in storage that has memcache/redis implementations we can add a change record in those issues with what needs to be done (if something does), I don't think we need to mention it yet when it's still theoretical.

catch’s picture

Status: Reviewed & tested by the community » Fixed

I've moved #3192487: Warn about upcoming JSON database support requirement in Drupal 9 back to 9.2.x since I think we can do most of that issue in a minor release and then just tweak it for Drupal 10.

Since that follow-up is open, I think we can mark this fixed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.