MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / main

Function main

test/perf/many_table_reflection.py:445–527  ·  view source on GitHub ↗
(db, schema_name, table_number, min_cols, max_cols, args)

Source from the content-addressed store, hash-verified

443
444
445def main(db, schema_name, table_number, min_cols, max_cols, args):
446 timing = timer()
447 if args.pool_class:
448 engine = sa.create_engine(
449 db,
450 echo=args.echo,
451 poolclass=getattr(sa.pool, args.pool_class),
452 future=True,
453 )
454 else:
455 engine = sa.create_engine(db, echo=args.echo, future=True)
456
457 if args.drop_all:
458 return drop_all(engine, schema_name)
459
460 if engine.name == "oracle":
461 # clear out oracle caches so that we get the real-world time the
462 # queries would normally take for scripts that aren't run repeatedly
463 with engine.connect() as conn:
464 # https://stackoverflow.com/questions/2147456/how-to-clear-all-cached-items-in-oracle
465 conn.exec_driver_sql("alter system flush buffer_cache")
466 conn.exec_driver_sql("alter system flush shared_pool")
467 if not args.no_create:
468 print(
469 f"Generating {table_number} using engine {engine} in "
470 f"schema {schema_name or 'default'}",
471 )
472 meta = sa.MetaData()
473 table_names = []
474 stats = {}
475 try:
476 if not args.no_create:
477 with timing("populate-meta"):
478 meta = generate_meta(
479 schema_name, table_number, min_cols, max_cols, engine.name
480 )
481 with timing("create-tables"):
482 create_tables(engine, meta)
483
484 with timing("get_table_names"):
485 with engine.connect() as conn:
486 table_names = engine.dialect.get_table_names(
487 conn, schema=schema_name
488 )
489 print(
490 f"Reflected table number {len(table_names)} in "
491 f"schema {schema_name or 'default'}"
492 )
493 mode = {"single", "multi"}
494 if args.multi_only:
495 mode.discard("single")
496 if args.single_only:
497 mode.discard("multi")
498
499 if args.sqlstats:
500 print("starting stats for subsequent tests")
501 stats = _apply_events(engine)
502 for test_name, test_fn in tests.items():

Callers 2

goMethod · 0.50

Calls 13

timerFunction · 0.85
drop_allFunction · 0.85
generate_metaFunction · 0.85
create_tablesFunction · 0.85
_apply_eventsFunction · 0.85
reflect_tablesFunction · 0.85
drop_tablesFunction · 0.85
_print_query_statsFunction · 0.85
connectMethod · 0.45
exec_driver_sqlMethod · 0.45
get_table_namesMethod · 0.45
discardMethod · 0.45

Tested by 1

goMethod · 0.40