Skip to content

Instantly share code, notes, and snippets.

@joegaudet
Created February 28, 2018 00:28
Show Gist options
  • Select an option

  • Save joegaudet/19fa749b5494bb662774e6c64303a992 to your computer and use it in GitHub Desktop.

Select an option

Save joegaudet/19fa749b5494bb662774e6c64303a992 to your computer and use it in GitHub Desktop.
SELECT
"orders"."id" as orders_id,
"clients"."id" as clients_id,
"users"."id" as users_id,
"users"."updated_at" as users_updated_at FROM "orders"
INNER JOIN "clients" ON "clients"."id" = "orders"."client_id" AND "clients"."deleted_at" IS NULL
INNER JOIN "clients_admins" ON "clients_admins"."client_id" = "clients"."id"
INNER JOIN "users" ON "users"."id" = "clients_admins"."user_id" WHERE "orders"."id" = 149784;
-- query plan
Nested Loop (cost=0.26..8.47 rows=1 width=20) (actual time=0.032..0.033 rows=1 loops=1)
-> Nested Loop (cost=0.20..8.23 rows=1 width=12) (actual time=0.025..0.026 rows=1 loops=1)
-> Nested Loop (cost=0.14..8.15 rows=1 width=12) (actual time=0.018..0.018 rows=1 loops=1)
-> Index Scan using orders_pkey on orders (cost=0.08..4.09 rows=1 width=8) (actual time=0.011..0.011 rows=1 loops=1)
Index Cond: (id = 149784)
-> Index Scan using clients_pkey on clients (cost=0.06..4.06 rows=1 width=4) (actual time=0.006..0.006 rows=1 loops=1)
Index Cond: (id = orders.client_id)
Filter: (deleted_at IS NULL)
-> Index Only Scan using index_clients_admins_on_client_id_and_user_id on clients_admins (cost=0.06..0.08 rows=1 width=8) (actual time=0.005..0.005 rows=1 loops=1)
Index Cond: (client_id = clients.id)
Heap Fetches: 1
-> Index Scan using users_pkey on users (cost=0.06..0.23 rows=1 width=12) (actual time=0.005..0.005 rows=1 loops=1)
Index Cond: (id = clients_admins.user_id)
Planning time: 0.942 ms
Execution time: 0.103 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment