Node revision keys could be better indexed

Created on 8 April 2011, over 13 years ago
Updated 15 June 2023, about 1 year ago

MySQL5 supports compound Primary keys, and a "smart" auto_incrementer. I don't know if Postgres or other DB engines do, but this could offer a significant improvement in the database lifecycle and storage capacity of a Drupal site. It may even improve indexing.

To understand what I'm referring to, look at the "animals" demo code in: http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html

Basically, what I see in Drupal 6 and 7 in the node_revision table is this: the Revision ID is the primary key and auto_increments on its own. That's acceptable, but the key design could be improved. Because MySQL offers compound primary keys, we could set it up like such: (i'm leaving out additional fields for the sake of this example).

create table node_revision (
  nid int unsigned not null,
  vid int unsigned auto_increment not null,
  uid int unsigned not null,
  title char(255) not null default 'Untitled',
  PRIMARY KEY (nid, vid)
);

insert into node_revision (nid,uid,title) values 
(1, 1, 'My Test node'),
(1, 1, 'I renamed my Test node'),
(1, 1, 'I fixed the name of my test node'),
(2, 1, 'This is a different node'),
(2, 1, 'I renamed my different node'),
(2, 1, 'I renamed the different node again'),
(3, 1, 'Pretty, cool, huh?');

select * from node_revision;

See the vid field? It only increases when an NID&VID are already present. (And yes, I did show title as "char" instead of "varchar" because its easier for mysql to index and read than a variable width field.)

In this manner, every time a revision is created, it's not indexing from the highest revision number already in the database, its starting from the highest revision number known on that node. The advantage is that our row limit in every table with revisioning increases from 2.1bn records to (2.1*2.1)bn records.

Nodes aside, I feel this could be applied to any table that handles revisioning, and would really like to see it implemented into Drupal 8. Ideally, modules that manage revisions of their own content could do this in this manner as well.

✨ Feature request
Status

Postponed: needs info

Version

9.5

Component
DatabaseΒ  β†’

Last updated less than a minute ago

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

πŸ‡ΊπŸ‡ΈUnited States wjaspers

Live updates comments and jobs are added and updated live.
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.71.5 2024