TUNE H3C USING THE POSTGRESQL CONFIGURATION
-------------------------------------------------------------------------------
G.Landais (CDS)
-------------------------------------------------------------------------------
H3C indexes tables using the function h3c_ang2ipix() to get the HEALPix number
from a position. This kind of indexation is efficient and used easily by the
PostgreSQL engine when you query an indexed table using this function.
ex: SELECT * FROM tables WHERE h3c_ang2ipix(ra,de) = healpix_number
In the context of a cone search, a polygon search or a crossmatch, H3C provides
the functions h3c_radial_query(), h3c_poly_query() and h3c_join().
These functions use the function h3c_ang2ipix (the main function of H3C) in a
complex query. In some case, the PostgreSQL QUERY PLAN could ignore the H3C
indexation with choosing a bad sequential can.
This note lists some ways to force the H3C indexation with using the PostgreSQL
tools.
-------------------------------------------------------------------------------
THE SPECIAL CASE OF THE JOIN BY POSITIONS
h3c_join is dedicated to join tables according to their position. This function
is more adapted for this usage than h3c_radial_query.
The order of the parameters in the h3c_join function is important: the first
columns should be the smallest table.
ex: it table1 has less records than table2
SELECT count(*) FROM table1, table2
WHERE h3c_join(table1.ra,table1.de,table2.ra,table2.de,2/3600.)
-------------------------------------------------------------------------------
FORCE THE ENGINE TO CHOOSE THE INDEXATION
In PostgreSQL, there are differents ways to force an index:
- In the SQL session: set the configuration parameters "enable_seqscan" and
enable_nestloop" to false and be sure than the parameter "enable_indexscan" is
set to true!
set enable_seqscan=false ;
set enable_nestloop=false ;
set enable_indexscan=true ;
Note: this way is usually sufficient!
- Modify the general configuration of PostgreSQL in the postgresql.conf.
Attention! this change will be taken in account for the entire database!
Decrease the value of "seq_page_cost" and "random_page_cost" used by the
PostgreSQL engine to compute a weight to choose the scan method (seqscan,
indexscan or nestloop). Decreasing seq_page_cost and random_page_cost gives
less weight to sequantial scan in favor to index scan.
In my configuration I decrease the value to 0.1 for the both parameters.
- Improve the usage of memory :
- in increasing the size of cache memory used in the QUERY PLAN :
example: effective_cache_size = 2048MB
- in increasing the size of memory to cache the disk
example: shared_buffers = 2048Mb
- At least , you can modify the nside used by H3C (default is 32768=2^15) with
specifying the nside in the H3C functions in the queries AND during the
index creation:
h3c_ang2ipix(ra,de,nside)
h3c_radial_query(...,nside)
h3c_join(...,nside)
CREATE INDEX indename ON table (h3c_ang2ipix(ra,de,nside))