Issue
I'm trying to understand how the .explain()
function works in Django ORM.
The official documentation here says this.
print(Blog.objects.filter(title='My Blog').explain())
gives below output.
Seq Scan on blog (cost=0.00..35.50 rows=10 width=12) Filter: (title
= 'My Blog'::bpchar)
But if I try to print the same thing in my local Django shell, it is giving me different output like below.
print(OCUser.objects.all().explain())
gives
SIMPLE alyssa_ocuser None ALL None None None None 2853 100.0 None
which is not similar to the one in the official documentation.
I'm not sure what this SIMPLE, and all those None values are. Can someone please explain?
When I filter the query, I'm getting as below.
print(OCUser.objects.filter(chain_code=110).explain(format='text'))
1 SIMPLE alyssa_ocuser None ALL None None None None 2853 10.0 Using where
Am I doing something wrong?
Python: 3.7.3
Django: 2.1.5
Mysql: Ver 14.14 Distrib 5.7.26
Solution
The explain()
literally translates to raw SQL EXPLAIN
which is specific to the Database we are using.
In the official documentation, they've used Postgres where as I was using MySQL DB.
I got the output specific to MySQL which is same as EXPLAIN SELECT * FROM TABLE_NAME
.
Answered By - Underoos
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.