We're using Galera and it's recommended that all tables have a primary key:

https://mariadb.com/kb/en/mariadb/mariadb-galera-cluster-known-limitations/

AFAIK it's also required for any other type of replication and in fact recommended for single nodes if using InnoDB.

On our server with many different Drupal websites (D7/D8), I've created a small script to search for tables without a primary key. Many minior issues I could solve (most of the time by adding a PK manually) and now one of the very few remaining tables is search_api_db_default (all D8 websites) where "default" is think is the index name. I'm unsure on how to proceed here. Would it be sufficient to add a primary key for the "item_id" column? Is this column unique or could this cause conflicts? Of course, it would be even better if the Search API module did this automatically during index creation. That's why I'm filing this bug report.

Comments

rgpublic created an issue. See original summary.

drunken monkey’s picture

Component: General code » Database backend
Priority: Normal » Major
Status: Active » Needs review
StatusFileSize
new4.95 KB
new14.28 KB

Oh, thanks a lot for catching that!
As you can see in \Drupal\search_api_db\Plugin\search_api\backend\Database::createFieldTable(), we actually already have code for adding a primary key. However, it seems there is currently a bug in there with the return; in the middle of the method triggering for those denormalized table and thus preventing the primary key from being added.

The attached patch should fix this, and includes not only an update hook and a test, but also a test for the update hook (my first – hope it works).
Please test/review!
And thanks again for creating this issue!

Status: Needs review » Needs work

The last submitted patch, 2: 2884451-2--fix_db_backend_tables_primary_key.patch, failed testing. View results

drunken monkey’s picture

Status: Needs work » Needs review

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

The tests looks solid. Let's get this in!

  • drunken monkey committed b1c9a48 on 8.x-1.x
    Issue #2884451 by drunken monkey: Fixed missing primary key for...
drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Thanks a lot for reviewing!
Committed.
Also thanks again for the initial bug report, rgpublic!

Status: Fixed » Closed (fixed)

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