Handle empty tables in concurrency support for MySQL.

When the table is empty we get nil for min and max values of the id column.
In that case we don't compute a set of ranges and “cancel” concurrency
support for the empty table.

Fixes #596.
This commit is contained in:
Dimitri Fontaine 2017-07-18 13:35:01 +02:00
parent b1fa3aec3c
commit d37ad27754

View File

@ -58,8 +58,14 @@
(sql (format nil "select min(`~a`), max(`~a`) from `~a`"
col col (table-source-name (source mysql)))))
(destructuring-bind (min max)
(mapcar #'parse-integer (first (mysql-query sql)))
(let ((result (first (mysql-query sql))))
;; result is (min max), or (nil nil) if table is empty
(if (or (null (first result))
(null (second result)))
result
(mapcar #'parse-integer result)))
;; generate a list of ranges from min to max
(when (and min max)
(let ((range-list (split-range min max *rows-per-range*)))
(unless (< (length range-list) concurrency)
;; affect those ranges to each reader, we have CONCURRENCY
@ -76,7 +82,7 @@
:columns (columns mysql)
:transforms (transforms mysql)
:encoding (encoding mysql)
:range-list (cons col part)))))))))))))
:range-list (cons col part))))))))))))))
(defmacro with-encoding-handler (&body forms)
`(handler-bind