Skip to content

Instantly share code, notes, and snippets.

@exit99
Last active August 29, 2015 14:25
Show Gist options
  • Save exit99/cb2d58234485310c7486 to your computer and use it in GitHub Desktop.
Save exit99/cb2d58234485310c7486 to your computer and use it in GitHub Desktop.
SQLA Alchemy exists speed test
Assume `Ticket.query` == session.query(Ticket).
This is done a table with 400,000+ rows and 0-40 rows where there is identical client_id fields.
1. bool(Ticket.query.filter_by(client_id=1111).count())
2. Ticket.query.with_entities(exists().where(Ticket.client_id == 1111)).scalar()
Results
1. 2.
20584 10622
25934 7449
20154 8009
23342 7439
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment