Gracefully handle complex queries that can't be parsed
macbre opened this issue · 1 comments
macbre commented
mysql> explain SELECT val, count(*) FROM 0020_big_table WHERE id BETWEEN 10 AND 20;
ERROR 1140 (42000): In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'index_digest.0020_big_table.val'; this is incompatible with sql_mode=only_full_group_by
mysql> SELECT t.val as value, count(*) FROM 0020_big_table as t WHERE id BETWEEN 10 AND 20 GROUP BY val;
+-------+----------+
| value | count(*) |
+-------+----------+
| 2 | 1 |
| 3 | 5 |
| 4 | 5 |
+-------+----------+
3 rows in set (0,00 sec)
macbre commented
Traceback (most recent call last):
File "/home/macbre/src/git/index-digest/env3/bin/index_digest", line 11, in <module>
load_entry_point('indexdigest', 'console_scripts', 'index_digest')()
File "/home/macbre/src/git/index-digest/indexdigest/cli/script.py", line 109, in main
print(format_plain(database, reports))
File "/home/macbre/src/git/index-digest/indexdigest/formatters/plain.py", line 34, in format_plain
reports = list(reports)
File "/home/macbre/src/git/index-digest/indexdigest/linters/linter_0002_not_used_indices.py", line 22, in check_not_used_indices
for (query, table_used, index_used, _) in explain_queries(database, queries):
File "/home/macbre/src/git/index-digest/indexdigest/utils.py", line 52, in explain_queries
for row in database.explain_query(query):
File "/home/macbre/src/git/index-digest/indexdigest/utils.py", line 86, in memoized_func
cache[key] = func(*args, **kwargs)
File "/home/macbre/src/git/index-digest/indexdigest/database.py", line 229, in explain_query
return list(self.query_dict_rows('EXPLAIN {}'.format(sql)))
File "/home/macbre/src/git/index-digest/indexdigest/database.py", line 138, in query_dict_rows
for row in self.query(sql, cursor_class=DictCursor):
File "/home/macbre/src/git/index-digest/indexdigest/database.py", line 106, in query
raise IndexDigestQueryError(message)
indexdigest.database.IndexDigestQueryError: In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'index_digest.0020_big_table.val'; this is incompatible with sql_mode=only_full_group_by