I am performing a simple natural join on two big tables.
- polygons contains 68,000 rows (45 MB)
- roadshydro contains about 2 million rows(210 MB) .
Does that mean that the database engine makes a data set of 68,000*2 million rows while performing natural join internally? If so, then the amount of memory required must be 45*210 MB which is much larger than what my system has, which is only 1.5 GB.
When I executed this Query, after 5 minutes my system crashes (abrupty shuts down). Can't it handle 250 MB of data on the database? What good for are databases then?
"I am modifying the above Question to clear the doubts of readers. 29-02-2012 today."
It seems many of my friends got confused because i mention 'natural join' word in the Question above. The real spatial Query i was using is :
select p.OID , r.OID
from poygons as p , roadshydro as r
Where st_intersects(p.the_geom , r.the_geom) ;
where polygons & roadshydro tables each has two fields : OID , the_geom . Clearly , it is a cross product of two tables and not Natural Join on some common key.
I monitor the main memory consumption When i execute the above query. It happens nothing. There is not a slightest amount of memory consumption , neither i get any output ever but CPU usage is almost 100%. It seems database isnt doing any computation at all. However , if i remove the where clause from the query , the Main memory consumption gradually goes too high (after 5-6 minutes ) resulting into system crash and machine abruptly shut down. This is what i am experiencing. What so special about removing the where clause? why postgres is failing to execute the query !! Surprised at this behaviour.
It really depends on many different factors, but most of all on the DBMS you are using and its configuration.
But to clear out the biggest misunderstanding: the DBMS does not have to hold all the rows in memory: it can write to a temporary table (on the harddisk) and serve you the result... slowly... so if it's crashing, that is not normal.
Then again, why are you asking 68k*2M rows? That is 136,000,000,000 rows! You sure you don't want a straight join on some key instead?