diff --git a/src/load/migrate-database.lisp b/src/load/migrate-database.lisp index d2e7578..c12e050 100644 --- a/src/load/migrate-database.lisp +++ b/src/load/migrate-database.lisp @@ -261,22 +261,17 @@ (view-list (copy-list (view-list catalog)))) ;; when materialized views are not supported, view-list is empty here (cond - ((notevery #'null (mapcar #'table-row-count-estimate table-list)) - (flet ((compare-row-count-estimates (a b) - (declare (type (or null fixnum) a b)) - (> (or a 0) (or b 0)))) - (let ((sorted-table-list (sort table-list - #'compare-row-count-estimates - :key #'table-row-count-estimate))) - (log-message :notice - "Processing tables in this order: ~{~a: ~d rows~^, ~}" - (loop :for table - :in (append sorted-table-list view-list) - :append (list (format-table-name table) - (table-row-count-estimate table)))) - (append sorted-table-list view-list)))) + ((notevery #'zerop (mapcar #'table-row-count-estimate table-list)) + (let ((sorted-table-list + (sort table-list #'> :key #'table-row-count-estimate))) + (log-message :notice + "Processing tables in this order: ~{~a: ~d rows~^, ~}" + (loop :for table :in (append table-list view-list) + :collect (format-table-name table) + :collect (table-row-count-estimate table))) + (nconc sorted-table-list view-list))) (t - (append table-list view-list))))) + (nconc table-list view-list))))) ;;; diff --git a/src/sources/common/api.lisp b/src/sources/common/api.lisp index 4b218cd..2c2ba3d 100644 --- a/src/sources/common/api.lisp +++ b/src/sources/common/api.lisp @@ -154,7 +154,7 @@ (:documentation "Get the list of foreign keys from the source database.")) (defgeneric fetch-table-row-count (catalog db-copy &key including excluding) - (:documentation "Get the estimate row count for tables in the source database")) + (:documentation "Retrieve and set the row count estimate for given tables.")) (defgeneric fetch-comments (catalog db-copy &key including excluding) (:documentation "Get the list of comments from the source database.")) diff --git a/src/sources/mysql/mysql-schema.lisp b/src/sources/mysql/mysql-schema.lisp index 9c2a9d4..99603a5 100644 --- a/src/sources/mysql/mysql-schema.lisp +++ b/src/sources/mysql/mysql-schema.lisp @@ -163,7 +163,7 @@ &key including excluding) - "Get the row count estimate for given MySQL tables." + "Retrieve and set the row count estimate for given MySQL tables." (loop :for (table-name count) :in (mysql-query (sql "/mysql/list-table-rows.sql" diff --git a/src/utils/catalog.lisp b/src/utils/catalog.lisp index 968408c..a74d676 100644 --- a/src/utils/catalog.lisp +++ b/src/utils/catalog.lisp @@ -48,7 +48,8 @@ table-list view-list matview-list extension-list sqltype-list) (defstruct table source-name name schema oid comment - storage-parameter-list tablespace row-count-estimate + storage-parameter-list tablespace + (row-count-estimate 0 :type fixnum) ;; field is for SOURCE field-list ;; column is for TARGET