Commit 4b22469e authored by Aurel's avatar Aurel

fix selection of index when order is ambigous

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13076 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 49150eeb
...@@ -1957,7 +1957,7 @@ class Catalog( Folder, ...@@ -1957,7 +1957,7 @@ class Catalog( Folder,
group_by_expression = str(group_by_expression) group_by_expression = str(group_by_expression)
sort_on = None sort_on = None
sort_key = [] sort_key_list = []
if sort_index is not None: if sort_index is not None:
new_sort_index = [] new_sort_index = []
for sort in sort_index: for sort in sort_index:
...@@ -1982,7 +1982,7 @@ class Catalog( Folder, ...@@ -1982,7 +1982,7 @@ class Catalog( Folder,
for (original_key, so, as_type) in sort_index: for (original_key, so, as_type) in sort_index:
key = getNewKeyAndUpdateVariables(original_key) key = getNewKeyAndUpdateVariables(original_key)
if key is not None: if key is not None:
sort_key.append(key) sort_key_list.append(key)
if as_type == 'int': if as_type == 'int':
key = 'CAST(%s AS SIGNED)' % key key = 'CAST(%s AS SIGNED)' % key
elif as_type: elif as_type:
...@@ -2001,7 +2001,7 @@ class Catalog( Folder, ...@@ -2001,7 +2001,7 @@ class Catalog( Folder,
except: except:
LOG('SQLCatalog', WARNING, 'buildSQLQuery could not build the new sort index', error=sys.exc_info()) LOG('SQLCatalog', WARNING, 'buildSQLQuery could not build the new sort index', error=sys.exc_info())
sort_on = '' sort_on = ''
sort_key = [] sort_key_list = []
for key in key_list: for key in key_list:
if not key_alias_dict.has_key(key): if not key_alias_dict.has_key(key):
...@@ -2048,11 +2048,21 @@ class Catalog( Folder, ...@@ -2048,11 +2048,21 @@ class Catalog( Folder,
limit_expression = str(limit_expression) limit_expression = str(limit_expression)
# force index if exists when doing sort as mysql doesn't manage them efficiently # force index if exists when doing sort as mysql doesn't manage them efficiently
if len(sort_key) > 0: if len(sort_key_list) > 0:
index_from_table = {} index_from_table = {}
# first group columns from a same table # first group columns from a same table
for key in sort_key: LOG("SQLCatalog.buildSQLQuery", ERROR, "sort_key = %s" %sort_key)
for key in sort_key_list:
try:
related_table, column = key.split('.') related_table, column = key.split('.')
except ValueError:
# key is not of the form table.column
# so get table from dict
if len(from_table_dict) != 1:
continue
column = key
related_table = from_table_dict.keys()[0]
table = from_table_dict[related_table] table = from_table_dict[related_table]
if not index_from_table.has_key(table): if not index_from_table.has_key(table):
index_from_table[table] = [column,] index_from_table[table] = [column,]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment