So i happened to look at a query created within Django ORM and I am curious as to how it will execute Here is the query.
SELECT "workflowengine_formdata"."id", "workflowengine_formdata"."formfield_id", "workflowengine_formdata"."user_id", "workflowengine_formdata"."flow_id", "workflowengine_formdata"."file", "workflowengine_formdata"."text", "workflowengine_formdata"."created_at", "workflowengine_formdata"."updated_at"
FROM "workflowengine_formdata"
INNER JOIN "workflowengine_formfield"
ON ("workflowengine_formdata"."formfield_id" = "workflowengine_formfield"."id")
WHERE ("workflowengine_formdata"."flow_id" = 19a2e198-3731-414e-b247-c2cd08e659df
AND "workflowengine_formfield"."stage_id" = 1
AND "workflowengine_formfield"."expert_search_criteria" = True)
I am wondering, when the query does get executed what gets executed first? Does the part of the where clause get executed
("workflowengine_formdata"."flow_id" = 19a2e198-3731-414e-b247-c2cd08e659df
AND "workflowengine_formfield"."stage_id" = 1
AND "workflowengine_formfield"."expert_search_criteria" = True)
or the on
"workflowengine_formdata"."formfield_id" = "workflowengine_formfield"."id"
I think the where clauses get executed first, because that will reduce the number of rows that will participate in the join. I think the "ON" part of the query will basically join a lot of rows which is counterproductive.