Fix non-deterministic projection in MySQL query.

In MySQL the information_schema.statistics table lists all indexes and
has a row per index column, which means that the index level properties
are duplicated on every row of the view.

Our query against that catalog was lazily assuming the classic and
faulty MySQL behavior where GROUP BY would allow non aggregated columns
to be reported even when the result isn't deterministic, this patch
fixes that by using a trick: the NON_UNIQUE column is 0 for a unique
index and 1 otherwise, so we sum the numbers and process 0 equality.

Fix #345 again.
This commit is contained in:
Dimitri Fontaine 2016-04-27 21:14:59 +02:00
parent 7af6c7ac41
commit 44b9ec81c9

View File

@ -213,7 +213,7 @@ order by table_name, ordinal_position"
(loop
:for (table-name name non-unique cols)
:in (mysql-query (format nil "
SELECT table_name, index_name, non_unique,
SELECT table_name, index_name, sum(non_unique),
cast(GROUP_CONCAT(column_name order by seq_in_index) as char)
FROM information_schema.statistics
WHERE table_schema = '~a'
@ -232,7 +232,7 @@ GROUP BY table_name, index_name;"
(index
(make-pgsql-index :name name ; further processing is needed
:primary (string= name "PRIMARY")
:unique (not (string= "1" non-unique))
:unique (string= "0" non-unique)
:columns (mapcar
#'apply-identifier-case
(sq:split-sequence #\, cols)))))