apachesolr_update_7013 changed the primary key on apachesolr_index_entities from just entity_id to both entity_id and entity_type.

There was a corresponding change to the schema, but there was a small typo which makes the declared schema incorrect.

Patch attached.

Comments

iamEAP’s picture

Priority: Minor » Normal
StatusFileSize
new960 bytes

Actually, this may be more than just a simple typo.

New installations since update_7013 was introduced will have the wrong primary key. We have to introduce a new update that fixes the primary key.

nick_vh’s picture

Status: Needs review » Closed (won't fix)

Hmm,

this is actually not wrong. All other tables should not be unique on entity_type since entity_type for apachesolr_index_entities_node is always node, the only table where this is different must be apachesolr_index_entities, because multiple entity types can be indexed here?

Marking as closed won't fix unless you can show me why this is problematic and why this would speed up queries?

iamEAP’s picture

Status: Closed (won't fix) » Needs review
StatusFileSize
new27.02 KB

Here's a screenshot from the Schema module's schema comparison report page:

Apachesolr Schema Mismatch

This isn't a query speed up issue, this is to say that there's an error in the way the schema is declared which requires a correction via a new hook_update_N().

nick_vh’s picture

Status: Needs review » Needs work

When I do the install of schema, it does not report any problems to me :
Update 7013 already does db_add_primary_key('apachesolr_index_entities', array('entity_id', 'entity_type'));
I still can't see the mistake, and other should not be changed to apachesolr_index_entities ($type versus $table)

nick_vh’s picture

Status: Needs work » Postponed (maintainer needs more info)
iamEAP’s picture

Status: Postponed (maintainer needs more info) » Needs review

I believe the inconsistency only happens if you install a fresh copy of apachesolr, since fresh installs don't go through all of the hook_update_N() calls.

In the end, as you said, we want the apachesolr_index_entities table to have a primary key which consists of both entity_id and entity_type because it can include entities of all sorts. Currently, due to this typo (which checks for the key "other" when $type is a value, not a key)...

-    if ($type == 'other') {
+    if ($type == 'apachesolr_index_entities') {

If you freshly install the module, the apachesolr_index_entities table will only include entity_id in its primary key because that's what's declared in the schema. The above portion of the patch will realign apachesolr_index_entities to what the primary key should be.

However, anyone who's cleanly installed the module as of update_7013 will have the wrong schema, even if we just add the above typo fix. As a result, to take care of people who are in this state, we have to add a new update_7014 that fixes the primary key for that table.

+
+/**
+ * Re-apply primary key change for apachesolr_index_entities introduced in 7013.
+ */
+function apachesolr_update_7015() {
+  // Brand new installations since update_7013 have the wrong primary key.
+  db_drop_primary_key('apachesolr_index_entities');
+  db_add_primary_key('apachesolr_index_entities', array('entity_id', 'entity_type'));
+}

For those who installed the module awhile ago and went through the update process through 7013, update_7015 should have no effect at all.

nick_vh’s picture

Status: Needs review » Needs work
  $types = array(
      'other' => 'apachesolr_index_entities',
      'node' => 'apachesolr_index_entities_node',
  );
...
  foreach ($types as $type => $table) {
...
    if ($type == 'other') {

What is not correct here? $type is the id of the value. Perhaps you are not looking at latest dev?

iamEAP’s picture

Status: Needs work » Needs review
StatusFileSize
new622 bytes

Ah, here we go.

The code you referenced was added (here) on February 24th; the schema was changed (here) on February 2nd to add the dual primary key.

Apachesolr Beta16 (which is what I cleanly installed with) was released with the schema change (latter patch), but not the schema mismatch fix (former patch). We still need an update to fix the schema for those in my shoes who cleanly installed with Beta16.

Here's the patch with just the update.

nick_vh’s picture

Status: Needs review » Fixed

Committed to D7. Thanks for your quick replies!

This is not applicable to 6.x-3.x so marking as fixed

nick_vh’s picture

Status: Fixed » Closed (fixed)