mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-26 10:54:32 +02:00
Improvements to most/least common values
* Record total_rows for each column * Record (value, count) if there is just a single distinct value * Do not calculate most/least common if all values are distinct * Calculate table count once per table, not once per column
This commit is contained in:
parent
5c176ccbe0
commit
d4b8d9e7a5
2 changed files with 11 additions and 5 deletions
|
|
@ -1357,7 +1357,7 @@ def insert_files(
|
|||
@cli.command(name="analyze-tables")
|
||||
@click.argument(
|
||||
"path",
|
||||
type=click.Path(file_okay=True, dir_okay=False, allow_dash=False),
|
||||
type=click.Path(file_okay=True, dir_okay=False, allow_dash=False, exists=True),
|
||||
required=True,
|
||||
)
|
||||
@click.argument("tables", nargs=-1)
|
||||
|
|
@ -1375,12 +1375,14 @@ def analyze_tables(
|
|||
if not tables:
|
||||
tables = db.table_names()
|
||||
todo = []
|
||||
table_counts = {}
|
||||
for table in tables:
|
||||
table_counts[table] = db[table].count
|
||||
for column in db[table].columns:
|
||||
todo.append((table, column.name))
|
||||
# Now we now how many we need to do
|
||||
for i, (table, column) in enumerate(todo):
|
||||
column_details = db[table].analyze_column(column)
|
||||
column_details = db[table].analyze_column(column, total_rows=table_counts[table])
|
||||
if save:
|
||||
db["_analyze_tables"].insert(
|
||||
column_details._asdict(), pk=("table", "column"), replace=True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue