--analyze option for create-index, insert, update commands, closes #379, closes #365

This commit is contained in:
Simon Willison 2022-01-10 17:36:41 -08:00
commit 1b84c175b4
4 changed files with 74 additions and 3 deletions

View file

@ -490,8 +490,15 @@ def index_foreign_keys(path, load_extension):
default=False,
is_flag=True,
)
@click.option(
"--analyze",
help="Run ANALYZE after creating the index",
is_flag=True,
)
@load_extension_option
def create_index(path, table, column, name, unique, if_not_exists, load_extension):
def create_index(
path, table, column, name, unique, if_not_exists, analyze, load_extension
):
"""
Add an index to the specified table covering the specified columns.
Use "sqlite-utils create-index mydb -- -column" to specify descending
@ -506,7 +513,11 @@ def create_index(path, table, column, name, unique, if_not_exists, load_extensio
col = DescIndex(col[1:])
columns.append(col)
db[table].create_index(
columns, index_name=name, unique=unique, if_not_exists=if_not_exists
columns,
index_name=name,
unique=unique,
if_not_exists=if_not_exists,
analyze=analyze,
)
@ -726,6 +737,11 @@ def insert_upsert_options(fn):
envvar="SQLITE_UTILS_DETECT_TYPES",
help="Detect types for columns in CSV/TSV data",
),
click.option(
"--analyze",
is_flag=True,
help="Run ANALYZE at the end of this operation",
),
load_extension_option,
click.option("--silent", is_flag=True, help="Do not show progress bar"),
)
@ -761,6 +777,7 @@ def insert_upsert_implementation(
default=None,
encoding=None,
detect_types=None,
analyze=False,
load_extension=None,
silent=False,
):
@ -853,7 +870,12 @@ def insert_upsert_implementation(
else:
docs = (fn(doc) or doc for doc in docs)
extra_kwargs = {"ignore": ignore, "replace": replace, "truncate": truncate}
extra_kwargs = {
"ignore": ignore,
"replace": replace,
"truncate": truncate,
"analyze": analyze,
}
if not_null:
extra_kwargs["not_null"] = set(not_null)
if default:
@ -950,6 +972,7 @@ def insert(
alter,
encoding,
detect_types,
analyze,
load_extension,
silent,
ignore,
@ -1005,6 +1028,7 @@ def insert(
truncate=truncate,
encoding=encoding,
detect_types=detect_types,
analyze=analyze,
load_extension=load_extension,
silent=silent,
not_null=not_null,
@ -1039,6 +1063,7 @@ def upsert(
default,
encoding,
detect_types,
analyze,
load_extension,
silent,
):
@ -1072,6 +1097,7 @@ def upsert(
default=default,
encoding=encoding,
detect_types=detect_types,
analyze=analyze,
load_extension=load_extension,
silent=silent,
)