avoid to scan column with include_name #1017
Replies: 1 comment 3 replies
-
Hi - There's nothing particularly time consuming in the "include_name" process, autogenerate is not necessarily optimized for lightning speed however under normal circumstances the time spent in "include_name" time is negligible, here's a demo: from alembic.autogenerate.api import AutogenContext
from unittest.mock import Mock
import timeit
def a_column_filter(name, type_, parent_names):
return name == "some name"
context_w_no_filters = AutogenContext(Mock(opts={}, as_sql=False), Mock())
context_w_one_filter = AutogenContext(
Mock(opts={"include_name": a_column_filter}, as_sql=False), Mock()
)
def run_filters(context, colname):
context.run_name_filters(
colname,
"column",
{"table_name": "some_table", "schema_name": "some_schema"},
)
print(
"context with no filters:",
timeit.timeit(
"run_filters(context_w_no_filters, 'some name')",
"from __main__ import run_filters, context_w_no_filters",
number=1000000,
)
)
print(
"context with one filter:",
timeit.timeit(
"run_filters(context_w_one_filter, 'some name')",
"from __main__ import run_filters, context_w_one_filter",
number=1000000,
)
) running the include_name filter one million times without any filters takes .5 seconds, about .6 seconds for one filter present:
A database that has 5000 tables with 200 columns each , which would be immense and for which the reflection alone would take many minutes with current implementations, has 1M columns, so that's half a second of overhead. so we'd need to look at what your actual include_name filters are doing and see if that can be improved. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I have many table and each of them have lot of column and when I run automigration, alembic take a lot of time in include_name to scan all column.
I want to known if it's possible to avoid to scan columns in
include_name
when we run automigration.I don't have other idea to speed up this part on process.
thanks,
Beta Was this translation helpful? Give feedback.
All reactions