Problem/Motivation
FieldSqlStorageTest fails currently with PostgreSQL as database backend.
Indexes are quoted because they are used as identifiers, but when an index is used as in a WHERE clause in a query to pg_* table it should not be quoted because it will retain the case sensitivity within the single quotes.
Test Backtrace:
Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42704]: Undefined object: 7 ERROR: index "drupal_tpicg3wbwpdnvnnhwouxn5_gclwup2aowovvlxjh2ie_idx" does not exist: DROP INDEX drupal_TPIcG3WbwpdNvNNhwOuxN5_gCLwUP2AOWoVvlXjh2IE_idx; Array ( ) in Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema->updateDedicatedTableSchema() (line 1266 of /var/www/drupal8.dev/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php).
Drupal\Core\Database\Driver\pgsql\Connection->query('DROP INDEX drupal_TPIcG3WbwpdNvNNhwOuxN5_gCLwUP2AOWoVvlXjh2IE_idx')
Drupal\Core\Database\Driver\pgsql\Schema->dropIndex('entity_test_rev__testfield', 'testfield_value')
Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema->updateDedicatedTableSchema(Object, Object)
Proposed resolution
1. Remove quotes when ensureIdentifiersLength() is called on an index name being queried in pg_constraints or pg_index.
2. Clean up quoting of index and constraints by doing this in ensureIdentifiersLength() instead of directly in query method.
Remaining tasks
Write patch.
User interface changes
None.
API changes
None. ensureIdentifiersLength() is an internal driver protected method.
Comments
Comment #1
mradcliffeI may have been misled by the backtrace. I thought perhaps PostgreSQL returned 0 because the index name was lower case, and so I looked at using escapeTable() inside ensureIdentifiersLength(), and although that cleared the Exception there were several new assertion failures.
I see that this is quoted in the query statement, but not sure if it is relevant.
Here's the work-in-progress patch for this, which may have additional fails in other test groups. In case it helps.
Comment #2
daffie commentedThe FieldSqlStorageTest passes with this patch.
Comment #3
daffie commentedThis patch is a part of the patch from #2443659: PostgreSQL: Fix system\Tests\Entity\FieldSqlStorageTest.
Comment #4
bzrudi71 commentedDid a patch review and can confirm pass of test. Nothing obvious found, maybe we just need a bit more in terms of comments. Otherwise this seems RTBC to me, leaving this open for mradcliffe for another review.
Comment #5
mradcliffeI meant to review this on Saturday, but I got caught up in that other issue all afternoon.
I think this might be good with some clarification.
"Remove leading and trailing quotes because the index name is in a WHERE clause and not used as an identifier."
Other than that +1 for me though I think @bzrudi71's review has the least biased since I authored patches.
Comment #6
mradcliffeUpdated issue summary.
Comment #7
daffie commentedThe comment changes are RTBC for me.
Comment #8
bzrudi71 commentedLooks good to me :-) Thanks all!
Comment #9
webchickCommitted and pushed to 8.0.x. Thanks!