# \d credit Table "public.credit" Column | Type | Modifiers -----------+-----------------------------+----------------------------------------------------- id | integer | not null default nextval('credit_id_seq'::regclass) dated | timestamp without time zone | debit_id | integer | credit_id | integer | total | integer | note | character varying(255) | advert_id | integer | Indexes: "credit_pkey" PRIMARY KEY, btree (id) "credit_creditindex" btree (credit_id) "credit_datedindex" btree (dated) "credit_debitindex" btree (debit_id) Foreign-key constraints: "advert_id_exists" FOREIGN KEY (advert_id) REFERENCES advert(id) "credit_id_exists" FOREIGN KEY (credit_id) REFERENCES tg_user(id) "debit_id_exists" FOREIGN KEY (debit_id) REFERENCES tg_user(id) # explain SELECT credit.id, credit.dated, credit.debit_id, credit.credit_id, credit.total, credit.note, credit.advert_id FROM credit WHERE (((credit.credit_id) = (5624)) OR ((credit.debit_id) = (5624))) ORDER BY dated DESC LIMIT 30; QUERY PLAN -------------------------------------------------------------------------------------------------------- Limit (cost=0.00..1085.11 rows=30 width=50) -> Index Scan Backward using credit_datedindex on credit (cost=0.00..197996.92 rows=5474 width=50) Filter: ((credit_id = 5624) OR (debit_id = 5624))