Skip to content

Instantly share code, notes, and snippets.

View joevandyk's full-sized avatar

Joe Van Dyk joevandyk

View GitHub Profile
Limit (cost=7171333.18..7171333.18 rows=1 width=244) (actual time=14789.118..14789.119 rows=1 loops=1)
-> Sort (cost=7171333.18..7171504.71 rows=68611 width=244) (actual time=14789.115..14789.115 rows=1 loops=1)
Sort Key: r.created_at
Sort Method: top-N heapsort Memory: 25kB
-> Subquery Scan on r (cost=428255.95..7170990.13 rows=68611 width=244) (actual time=14688.773..14788.721 rows=150 loops=1)
-> HashAggregate (cost=428255.95..7170304.02 rows=68611 width=92) (actual time=14688.769..14788.396 rows=150 loops=1)
-> Nested Loop (cost=223442.35..427569.84 rows=68611 width=92) (actual time=12644.172..14632.360 rows=383 loops=1)
Join Filter: (ac.order_id = acli.order_id)
-> Nested Loop (cost=223441.93..404408.50 rows=46678 width=96) (actual time=12621.925..14603.351 rows=191 loops=1)
Join Filter: (ac.order_id = li.order_id)
Sort (cost=514690.51..514940.51 rows=100000 width=2548) (actual time=20856.993..20991.397 rows=100000 loops=1)
Sort Key: data.line_item_internal_id, data.shipment_picked_up_at
Sort Method: external merge Disk: 53536kB
CTE data
-> Limit (cost=2160.08..394324.69 rows=100000 width=904) (actual time=15.456..20009.395 rows=100000 loops=1)
-> Nested Loop Left Join (cost=2160.08..16722360.84 rows=4263567 width=904) (actual time=15.455..19990.996 rows=100000 loops=1)
-> Hash Left Join (cost=2159.22..10424474.68 rows=4016402 width=792) (actual time=14.872..14675.085 rows=99204 loops=1)
Hash Cond: (pl.shipping_export_id = se.id)
-> Nested Loop Left Join (cost=3.28..10347011.19 rows=4016402 width=767) (actual time=0.145..14552.755 rows=99204 loops=1)
-> Nested Loop Left Join (cost=2.85..8305866.58 rows=4016402 width=739) (actual time=0.143..13375.717 rows=99204 loops=1)
require 'sequel'
require 'active_record'
DB = Sequel.connect('postgres://localhost/tanga_dev')
puts DB[:users].count
ActiveRecord::Base.connection.instance_variable_set(:@connection, DB.synchronize{|c| c})
puts ActiveRecord::Base.connection.select_one('select count(*) from users')
# results in
curl https://gist.githubusercontent.com/joevandyk/d1f08cdc7b05fec0c971/raw/9e8da2ec2c2c7eb224e304fa89b7e2fe3fac9bb3/gistfile1.txt | sh
require 'que'
require 'logger'
require 'sequel'
# Preload MultiJson's code for finding most efficient json loader
# so we don't need to do this inside each worker process.
if defined?(MultiJson)
MultiJson.load('[]')
end
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------
Append (cost=0.00..65.76 rows=10 width=109) (actual time=0.126..0.126 rows=0 loops=1)
-> Seq Scan on medias (cost=0.00..0.00 rows=1 width=588) (actual time=0.000..0.000 rows=0 loops=1)
Filter: (id = 2)
-> Index Scan using channel_medias_pkey on channel_medias (cost=0.28..8.29 rows=1 width=66) (actual time=0.015..0.015 rows=0 loops=1)
Index Cond: (id = 2)
-> Index Scan using product_medias_id_media_of_id_idx on product_medias (cost=0.29..8.31 rows=1 width=58) (actual time=0.007..0.007 rows=0 loops=1)
Index Cond: (id = 2)
-> Index Scan using comment_medias_pkey on comment_medias (cost=0.28..8.30 rows=1 width=51) (actual time=0.014..0.014 rows=0 loops=1)
Aggregate (cost=24840126.64..24840126.65 rows=1 width=6) (actual time=13742.045..13742.046 rows=1 loops=1)
-> Seq Scan on orders (cost=0.00..24832943.33 rows=1436662 width=6) (actual time=2447.098..13741.666 rows=95 loops=1)
Filter: (SubPlan 1)
Rows Removed by Filter: 2884739
SubPlan 1
-> Index Scan using page_views_session_id_created_at_idx on page_views pv (cost=0.57..8.60 rows=1 width=0) (actual ti
me=0.003..0.003 rows=0 loops=2884834)
Index Cond: ((session_id = orders.session_id) AND (orders.created_on > created_at) AND (created_at > (now() - '2
days'::interval)))
Filter: (path = '/carts/resume'::citext)
Limit (cost=1.58..10202285.08 rows=5 width=4) (actual time=1411.210..1661.481 rows=5 loops=1)
-> Unique (cost=1.58..20125024428.69 rows=9863 width=4) (actual time=1411.209..1661.479 rows=5 loops=1)
-> Nested Loop (cost=1.58..20125024404.03 rows=9863 width=4) (actual time=1411.209..1661.473 rows=8 loops=1)
Join Filter: ((SubPlan 8) IS TRUE)
-> Nested Loop (cost=1.29..30771878.73 rows=19726 width=12) (actual time=1360.868..1473.461 rows=8 loops=1)
Join Filter: (ci.sku_id = s.id)
Rows Removed by Join Filter: 781965
-> Nested Loop Anti Join (cost=1.29..514635.91 rows=19726 width=12) (actual time=1335.537..1347.890 rows=8 loops=1)
-> Nested Loop (cost=0.86..476369.46 rows=62559 width=25) (actual time=1329.325..1347.381 rows=14 loops=1)
-> Index Scan using cart_items_cart_id_idx on cart_items ci (cost=0.43..183520.84 rows=95690 width=8) (a
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAzEMopbbFvXWydqJMh+GTWL9Q7F1NNtO3jr1J6abk8soAlBa6s+shWglASdfx4Lzb/dYi4fvhLD06wkot5HSRXqeGB1m7IShiEYhRu6+ouAEhBTgPwbV3YunuEAkPTzetJf0bht4FSWVKRxQWuZ1azKnniBlOiHcK1zg+VNpjkBIZF0Qo7tb4YFhB3EO1/3RzCvCK98/Qx01J9BbAU5dtSOjHZAj2z+2G7q7ydVOuM5Y9jBZjZdgKS8VvDVefsOXykgFPZssRaBTFuwsKSfQQ7kGrT5W9lqjm/O9HpnnGmUsOnVHXNGHmO3hyN9CmQs5lm4Dd/A6pSMmYruO+lhP/GQ== joe@laptop
begin;
create table t (something integer);
do $$
declare other integer;
begin
insert into t (something) values (1) returning other into other;
end $$ language plpgsql;