25M x 25M inner join (postgresql) performance
Although it is hard for me to understand the motivation for this kind of query, you cannot expect any kind of efficiency since the query results will not fit in main memory. If you want the results stored somehow, the only way to do it is through the COPY command (http://www.postgresql.org/docs/9.2/static/sql-copy.html). COPY has the advantage that once a row is retrieved from the query it goes directly to secondary storage. This way you actually have a chance for the query to finish after a few hours. Then, if needed you can use COPY again to load those results to another DB table.