Skip to content

Commit

Permalink
Merge pull request #1182 from nharkins/nh_use_table_columns_for_table…
Browse files Browse the repository at this point in the history
…s_also

eliminate unnecessary SHOW TABLES which breaks on Vitess
  • Loading branch information
amjith authored Dec 11, 2024
2 parents 38b886e + 1f05949 commit 8099add
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions mycli/completion_refresher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions mycli/sqlcompleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,13 @@ 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)
# 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)

Expand Down

0 comments on commit 8099add

Please sign in to comment.