From a96416a589733a4a8154e16e401e664245a44a25 Mon Sep 17 00:00:00 2001 From: Vincent Pelletier <vincent@nexedi.com> Date: Thu, 17 Jul 2008 14:32:24 +0000 Subject: [PATCH] Always allow MySQL to use primary key. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@22526 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ZSQLCatalog/SQLCatalog.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/product/ZSQLCatalog/SQLCatalog.py b/product/ZSQLCatalog/SQLCatalog.py index a2debe1beb..110b7861d4 100644 --- a/product/ZSQLCatalog/SQLCatalog.py +++ b/product/ZSQLCatalog/SQLCatalog.py @@ -2102,6 +2102,14 @@ class Catalog(Folder, for table in index_from_table.keys(): available_index_list = self.getIndex(table, index_from_table[table], key_list) if len(available_index_list) > 0: + # Always give MySQL a chance to use PRIMARY key. It is much faster if + # current table is used in a join on primary key than forcing it to + # use another index. + # Note: due to a bug (?) in MySQL (at least 5.0.45 community), it is + # a syntax error to put "PRIMARY" keyword anywere besides at first + # position. Hence the "insert(0". + if 'PRIMARY' not in available_index_list: + available_index_list.insert(0, 'PRIMARY') # tell mysql to use these index table = from_table_dict.pop(related_table) index_list_string = ', '.join(available_index_list) -- 2.30.9