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.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 2884451-2--fix_db_backend_tables_primary_key.patch | 14.28 KB | drunken monkey |
| #2 | 2884451-2--fix_db_backend_tables_primary_key--tests_only.patch | 4.95 KB | drunken monkey |
Comments
Comment #2
drunken monkeyOh, 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 thereturn;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!
Comment #5
drunken monkeyComment #7
borisson_The tests looks solid. Let's get this in!
Comment #9
drunken monkeyThanks a lot for reviewing!
Committed.
Also thanks again for the initial bug report, rgpublic!