question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

subqueryload isn't caching

See original GitHub issue

not sure what is happening here, but two things to note:

  1. the subqueryload never caches, period. not sure if this is dependent on being from the lazy loader or not.
  2. 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:closed
  • Created 2 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
zzzeekcommented, Jun 7, 2021

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.

0reactions
CaselITcommented, Jun 7, 2021

@zzzeek do you think it may be worth it to merge that change, so it’s easier to debug cache issues?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found