While running the 7101-upgrade on a 70k-sized database I noticed that there is no index on redhen_engagement.contact_id after creating that index the migration took only one second (as opposed to several minutes).

I had a look at the hook_schema implementation that define foreign keys - but even newly installed drupal sites missed those foreign keys (and therefore indexes on the affected columns). That's when I finally found: http://drupal.org/node/911352 .

In short: D7 simply ignores foreign keys defined in hook_schema(). All foreign keys need to be declared explicitly in hook_install() using ALTER TABLE.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

torotil’s picture

Status: Active » Needs review
FileSize
8.09 KB

Here's a patch that explicitly creates indexes for all sets of columns that are declared as foreign keys (if not already done) - including upgrade hooks.

torotil’s picture

Sorry for double-posting - d.o just had a weird error.

torotil’s picture

There were also some obsolete foreign-key entries in redhen_contact.install. I've fixed them too.

torotil’s picture

It seems that my update hook for redhen_engagement got lost. Here is the patch.

levelos’s picture

Status: Needs review » Fixed

Thanks torotil, committed with minor variations!

Status: Fixed » Closed (fixed)

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

  • Commit 59a955b on 7.x-1.x, tests, redhen-donation authored by torotil, committed by levelos:
    #1986022 by torotil, levelos: Add missing indexes due to drupal core not...

  • Commit 59a955b on 7.x-1.x, tests, redhen-donation, relation-roles authored by torotil, committed by levelos:
    #1986022 by torotil, levelos: Add missing indexes due to drupal core not...