There is such a request:
SELECT * FROM file file1 LEFT JOIN file file2 ON ((((file2.transaction_code)::text = '10'::text) AND ((file1.uid)::text = (file2.uid)::text))) LEFT JOIN file file3 ON (((((file3.transaction_code)::text = '02'::text) AND ((file1.uid)::text = (file3.uid)::text)) AND (file3.send_date > file1.send_date))) LEFT JOIN file file4 ON (((((file4.transaction_code)::text = '04'::text) AND ((file1.uid)::text = (file4.uid)::text)) AND (file4.send_date > file1.send_date))) LEFT JOIN file file5 ON (((((file5.transaction_code)::text = '07'::text) AND ((file1.uid)::text = (file5.uid)::text)) AND (file5.send_date > file1.send_date))) LEFT JOIN file file6 ON ((((((file6.turn_code)::text = '07'::text) AND ((file1.uid)::text = (file6.uid)::text)) AND (file6.complete = true)) AND (file6.send_date > file1.send_date))) LEFT JOIN error ON (((file1.uid)::text = (error.uid)::text)) WHERE (((file1.turn_code)::text = '01'::text) AND ((file1.transaction_code)::text = '01'::text)); It works so slowly, you need to do something about it. The first thing that came to mind was to replace JOIN with OR where possible. It turned out such a non-working thing:
SELECT * FROM file WHERE ((((file.transaction_code)::text = '10'::text) AND ((file.uid)::text = (file.uid)::text)) OR ((((file.transaction_code)::text = '02'::text) AND ((file.uid)::text = (file.uid)::text)) AND (file.send_date > file.send_date)) OR ((((file.transaction_code)::text = '04'::text) AND ((file.uid)::text = (file.uid)::text)) AND (file.send_date > file.send_date)) OR ((((file.transaction_code)::text = '07'::text) AND ((file.uid)::text = (file.uid)::text)) AND (file.send_date > file.send_date)) OR (((((file.turn_code)::text = '07'::text) AND ((file.uid)::text = (file.uid)::text)) AND (file.complete = true)) AND (file.send_date > file.send_date))) AND (((file.turn_code)::text = '01'::text) AND ((file.transaction_code)::text = '01'::text)); Such a thing loads a lot longer and displays an incorrect result. What to do ?
explain (analyze,buffers)? And what do you want to do? - Finejoin's on the same table? - faoxis(file1.uid)::text = (file2.uid)::text)difficulties. Is it impossible to compare these fields without casting? After all, type conversion does not allow the optimizer to use an index. And by the way, is there an index at all - Mikeselect * from tab where X=500shows the work on the primary key cost 8.31.select * from tab where X::text='500'gives a complete table lookup and cost 2193 - Mike