I found that a lot of the node_load() requests were taking a long time to complete for the node_revisions table. I checked this out by doing an EXPLAIN of the query and found that the join to the node_revisions table was not using an index.

It seems that the primary key for node_revisons is both nid and vid, but the majority of the queries only use n.vid = r.vid as vid like nid is a global sequentical field.

I am not sure if we need to change the primary index or add an additional index to the node_revisions file, but this does need to be fixed.

For myself I have added a new index, which has taken the main node_load() from 17ms to 1.6ms

CommentFileSizeAuthor
#8 schema_0.patch2.48 KBCvbge
#6 schema.patch1.33 KBgordon
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Bèr Kessels’s picture

Can you post a patch? or a SQL command so that we can test?
Devel.module confirms the extremely long queries here.

killes@www.drop.org’s picture

I've another report from Aaron Welch that an index is needed. Please provide a patch.

killes@www.drop.org’s picture

Priority: Critical » Normal

not critical

Zen’s picture

Related issue: 35548.

Clean 4.7 installs have a primary index of nid + vid.
Upgraded installations have nid and vid as separate indices.

-K

killes@www.drop.org’s picture

That would explain why I didn't see the problem. :p

Indeed:

PRIMARY KEY (`vid`),
KEY `nid` (`nid`),
KEY `uid` (`uid`)

If we agree that this is the better structure, then we should simply change the database schemas.

gordon’s picture

Status: Active » Needs review
FileSize
1.33 KB

I have investigated this further, and found that in update_146 the indexes were changed, but the schema was not.

Here is a patch which should fix the initial load. I have also changed the pgsql as well but I can't test it. I think it is right.

Zen’s picture

Status: Needs review » Needs work

@Gordon: pgSQL - nid shouldn't be a sequence in the node_revisions table. It should just be an index.

Looks good otherwise :)

Thanks,
-K

Cvbge’s picture

Status: Needs work » Needs review
FileSize
2.48 KB

Fixed missing "," in database.mysql, removed unneeded sequence in database.pgsql and modified updates.inc to reflect the changes.

Not tested, but look quite good.

gordon’s picture

I am reluctant to up this to critical, but this needs to be commited before RC, otherwise we will have a number of freshly installed Drupal Sites that will be running poorly because there is a missing index.

As you can see from my really basic tests above, without the index there is a significant proformance hit.

Zen’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, and checked update with a clean install of HEAD on MySQL.

Thanks
-K

gordon’s picture

Should we also be adding a new update so that sites that were created in the windows where this index was not created so that this issue is fixed on systems with this issue.

killes@www.drop.org’s picture

We usually don't do that.

killes@www.drop.org’s picture

Status: Reviewed & tested by the community » Fixed

committed.

Anonymous’s picture

Status: Fixed » Closed (fixed)