From 44b9ec81c9becdbd55f3981988084ffd82de240d Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Wed, 27 Apr 2016 21:14:59 +0200 Subject: [PATCH] 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. --- src/sources/mysql/mysql-schema.lisp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sources/mysql/mysql-schema.lisp b/src/sources/mysql/mysql-schema.lisp index 6d86409..7a7ab3c 100644 --- a/src/sources/mysql/mysql-schema.lisp +++ b/src/sources/mysql/mysql-schema.lisp @@ -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)))))