From 4b77930277c0f32b9433f8d640cb7fc285e033e1 Mon Sep 17 00:00:00 2001 From: Neil Harkins Date: Wed, 11 Dec 2024 12:01:21 -0800 Subject: [PATCH 1/2] eliminate unnecessary SHOW TABLES which breaks on Vitess --- mycli/completion_refresher.py | 5 +++-- mycli/sqlcompleter.py | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mycli/completion_refresher.py b/mycli/completion_refresher.py index eb684b55..662dd331 100644 --- a/mycli/completion_refresher.py +++ b/mycli/completion_refresher.py @@ -114,8 +114,9 @@ def refresh_schemata(completer, executor): @refresher("tables") def refresh_tables(completer, executor): - completer.extend_relations(executor.tables(), kind="tables") - completer.extend_columns(executor.table_columns(), kind="tables") + table_columns_dbresult = list(executor.table_columns()) + completer.extend_relations(table_columns_dbresult, kind="tables") + completer.extend_columns(table_columns_dbresult, kind="tables") @refresher("users") diff --git a/mycli/sqlcompleter.py b/mycli/sqlcompleter.py index 44344cbd..5a46ce8e 100644 --- a/mycli/sqlcompleter.py +++ b/mycli/sqlcompleter.py @@ -1010,6 +1010,9 @@ def extend_columns(self, column_data, kind): metadata = self.dbmetadata[kind] for relname, column in column_data: + if relname not in metadata[self.dbname]: + _logger.error("relname '%s' was not found in db '%s'", relname, self.dbname) + continue metadata[self.dbname][relname].append(column) self.all_completions.add(column) From 1f0594967437d4fdd5ae4fa0ef34873ff2f7485f Mon Sep 17 00:00:00 2001 From: Neil Harkins Date: Wed, 11 Dec 2024 15:01:18 -0800 Subject: [PATCH 2/2] add comment --- mycli/sqlcompleter.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mycli/sqlcompleter.py b/mycli/sqlcompleter.py index 5a46ce8e..16362899 100644 --- a/mycli/sqlcompleter.py +++ b/mycli/sqlcompleter.py @@ -1012,6 +1012,10 @@ def extend_columns(self, column_data, kind): for relname, column in column_data: if relname not in metadata[self.dbname]: _logger.error("relname '%s' was not found in db '%s'", relname, self.dbname) + # this could happen back when the completer populated via two calls: + # SHOW TABLES then SELECT table_name, column_name from information_schema.columns + # it's a slight race, but much more likely on Vitess picking random shards for each. + # see discussion in https://github.com/dbcli/mycli/pull/1182 (tl;dr - let's keep it) continue metadata[self.dbname][relname].append(column) self.all_completions.add(column)