Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
3n -> n query playground
SELECT * FROM (
SELECT "functions".* FROM "functions" WHERE "functions"."klass_id" = 242 AND "functions"."name" = 'change'
UNION
SELECT "functions".* FROM "functions" WHERE "functions"."klass_id" = 661 AND "functions"."name" = 'change'
UNION
SELECT "functions".* FROM "functions" INNER JOIN "klasses" ON "klasses"."id" = "functions"."klass_id" INNER JOIN "versions" ON "versions"."id" = "klasses"."version_id" WHERE "versions"."id" = 1 AND "functions"."name" = 'change'
) as subquery LIMIT 1
however postgres will execute all union queries even if the first query returns a result
Function Load (0.4ms) SELECT "functions".* FROM "functions" WHERE "functions"."klass_id" = $1 AND "functions"."name" = $2 LIMIT $3 [["klass_id", 242], ["name", "change"], ["LIMIT", 1]]
↳ lib/libnotes/html/docs_reference_filter.rb:24:in `block in find_matching_function_for'
Function Load (0.3ms) SELECT "functions".* FROM "functions" WHERE "functions"."klass_id" = $1 AND "functions"."name" = $2 LIMIT $3 [["klass_id", 661], ["name", "change"], ["LIMIT", 1]]
↳ lib/libnotes/html/docs_reference_filter.rb:24:in `block in find_matching_function_for'
Function Load (1.5ms) SELECT "functions".* FROM "functions" INNER JOIN "klasses" ON "klasses"."id" = "functions"."klass_id" INNER JOIN "versions" ON "versions"."id" = "klasses"."version_id" WHERE "versions"."id" = $1 AND "functions"."name" = $2 LIMIT $3 [["id", 1], ["name", "change"], ["LIMIT", 1]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment