mirror of
https://github.com/dimitri/pgloader.git
synced 2026-05-04 18:36:12 +02:00
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:
parent
7af6c7ac41
commit
44b9ec81c9
@ -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)))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user