subqueryload isn't caching
See original GitHub issuenot sure what is happening here, but two things to note:
- the subqueryload never caches, period. not sure if this is dependent on being from the lazy loader or not.
- it is using the lazy loader’s cache, which seems a little strange
Running this with -Werror hits the size alert for the A.b lazyloader.
from sqlalchemy import Column
from sqlalchemy import create_engine
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy.orm import Session
Base = declarative_base()
class A(Base):
__tablename__ = "a"
id = Column(Integer, primary_key=True)
b_id = Column(ForeignKey("b.id"))
b = relationship("B")
class B(Base):
__tablename__ = "b"
id = Column(Integer, primary_key=True)
c1 = relationship("C1", lazy="subquery")
class C1(Base):
__tablename__ = "c1"
id = Column(Integer, primary_key=True)
b_id = Column(ForeignKey("b.id"))
e = create_engine("sqlite://", echo=True)
Base.metadata.create_all(e)
s = Session(e)
s.add(
A(
b=B(
c1=[C1()],
)
)
)
s.commit()
def go():
s.close()
a1 = s.query(A).first()
a1.b
for i in range(50):
go()
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Relationship Loading Techniques
The subqueryload strategy has many advantages over joined eager loading in the area of loading collections. First, it allows the original query ...
Read more >SQLAlchemy eager loading multiple relationships
For a one-to-many or many-to-many relationship, it's (usually) better to use subqueryload instead, for performance reasons:
Read more >deeply recursive options are inefficient · Issue #8142 - GitHub
so with #8126, the stack_selectinload(150) given here emits a warning, cache is turned off, it doesn't perform great but it gets all the...
Read more >Problem overriding subquery caching - Oracle Communities
I have tried to running the subquery inside a CTE and outside a CTE with a predicate that I thought would fix this...
Read more >Bug #615752 “Subquery caching is not visible in EXPLAIN”
Subquery caching is currently only detectable via SHOW STATUS LIKE 'Subquery_cache_hit' which does not scale well for automatic testing.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
well im going to remove the warning from the loader strategies altogether so the warning won’t be seen anymore. for the main cache, im not sure what we’d do with a dump of 700 items, so while ther are some debugging features on cachekey im not sure about the dump feature.
@zzzeek do you think it may be worth it to merge that change, so it’s easier to debug cache issues?