On 2 December 2015 at 20:51, shili <shi_li_1...@163.com> wrote: > I had saw this sentence: SQL statements that use the EXISTS condition in > PostgreSQL are very inefficient since the sub-query is RE-RUN for EVERY row > in the outer query's table. There are more efficient ways to write most > queries, that do not use the EXISTS condition. So,I want to know how > PostgreSQL to implement the EXISTS condition? Is that sentence true? and,if > that is true,are there any methods to import the performance of the EXISTS > condition?
That sounds like it might be quite out-dated information. Semi joins have been supported for around 7 years. See http://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=e006a24ad152b3faec748afe8c1ff0829699b2e6 However, there are cases where this is still not possible, for example if the subquery contains a volatile function, or perhaps a LIMIT or OFFSET. You can view the output from the planner by prefixing your SELECT statement with EXPLAIN: See http://www.postgresql.org/docs/current/static/sql-explain.html This will give you the information you need to see how the query planner has decided on how your query will be executed. -- David Rowley http://www.2ndQuadrant.com/ <http://www.2ndquadrant.com/> PostgreSQL Development, 24x7 Support, Training & Services