Query took more than 2 mins for the first execution

30 Views Asked by At

The following query takes 2 minutes for the first time and 4 seconds from the next executions. I've created indexes for the necessary columns which are involved in this query even though I couldn't see any performance. Also, we've created a tab1 as Partition table.

Explain Plan

"Limit  (cost=53.33..224.13 rows=100 width=8) (actual time=41089.421..79505.769 rows=100 loops=1)"
"  ->  Merge Join  (cost=53.33..1079036.91 rows=631734 width=8) (actual time=41089.419..79505.743 rows=100 loops=1)"
"        Merge Cond: (co.oid = cof.oid)"
"        ->  Merge Append  (cost=2.64..475615.43 rows=10834163 width=8) (actual time=13.200..1877.923 rows=9121151 loops=1)"
"              Sort Key: co.oid"
"              ->  Index Only Scan using tab1_p1_pkey on tab1_p1 co_1  (cost=0.43..46920.23 rows=1806387 width=8) (actual time=1.677..168.544 rows=1520231 loops=1)"
"                    Heap Fetches: 0"
"              ->  Index Only Scan using tab1_p2_pkey on tab1_p2 co_2  (cost=0.43..46902.78 rows=1805757 width=8) (actual time=1.673..160.753 rows=1520721 loops=1)"
"                    Heap Fetches: 0"
"              ->  Index Only Scan using tab1_p3_pkey on tab1_p3 co_3  (cost=0.43..46890.40 rows=1805198 width=8) (actual time=1.657..170.122 rows=1519152 loops=1)"
"                    Heap Fetches: 0"
"              ->  Index Only Scan using tab1_p4_pkey on tab1_p4 co_4  (cost=0.43..46936.86 rows=1806962 width=8) (actual time=1.831..166.643 rows=1521707 loops=1)"
"                    Heap Fetches: 0"
"              ->  Index Only Scan using tab1_p5_pkey on tab1_p5 co_5  (cost=0.43..46875.35 rows=1804728 width=8) (actual time=2.897..168.518 rows=1519349 loops=1)"
"                    Heap Fetches: 0"
"              ->  Index Only Scan using tab1_p6_pkey on tab1_p6 co_6  (cost=0.43..46889.39 rows=1805131 width=8) (actual time=3.459..167.422 rows=1519996 loops=1)"
"                    Heap Fetches: 0"
"        ->  Index Scan using pk_tab2 on tab2 cof  (cost=0.43..568489.65 rows=631734 width=8) (actual time=40037.266..77273.203 rows=100 loops=1)"
"              Filter: ((creationdateft >= '129212064000000000'::bigint) AND (creationdateft <= '129212927990000000'::bigint))"
"              Rows Removed by Filter: 8972414"
"Planning Time: 753.626 ms"
"Execution Time: 79505.905 ms"

Query

SELECT CO.OID AS CO_OID
FROM schema1.tab1 CO 
INNER JOIN  schema1.tab2 COF ON (COF.OID = CO.OID)
WHERE (COF.CreationDateFT >= 129212064000000000) AND (COF.CreationDateFT <= 129212927990000000)
ORDER BY CO.OID 
LIMIT 100

Created necessary indexes for the columns which are involved. Expecting recommendations for the query performance improvement.

0

There are 0 best solutions below