]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add a test / comment about test_orm_query
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 1 Jun 2020 20:26:41 +0000 (16:26 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 1 Jun 2020 20:26:41 +0000 (16:26 -0400)
Change-Id: I8d78b3e75127141da177f711fd91216391a3c859

examples/performance/short_selects.py

index 2f2b19c17d75970cb735f66624e5c925dfff3f2d..64d9b05516126165a68694aba5f2ebddfdc2b7db 100644 (file)
@@ -75,6 +75,25 @@ def test_orm_query(n):
         session.query(Customer).filter(Customer.id == id_).one()
 
 
+@Profiler.profile
+def test_orm_query_newstyle(n):
+    """test a straight ORM query of the full entity."""
+
+    # the newstyle query is faster for the following reasons:
+    # 1. it uses LABEL_STYLE_DISAMBIGUATE_ONLY, which saves on a huge amount
+    # of label generation and compilation calls
+    # 2. it does not use the Query @_assertions decorators.
+
+    # however, both test_orm_query and test_orm_query_newstyle are still
+    # 25-30% slower than the full blown Query version in 1.3.x and this
+    # continues to be concerning.
+
+    session = Session(bind=engine)
+    for id_ in random.sample(ids, n):
+        stmt = future_select(Customer).where(Customer.id == id_)
+        session.execute(stmt).scalars().unique().one()
+
+
 @Profiler.profile
 def test_orm_query_cols_only(n):
     """test an ORM query of only the entity columns."""