getting ERROR: stack depth limit exceeded on a WHERE IN query on a view - Mailing list pgsql-novice

From Aditya Rastogi
Subject getting ERROR: stack depth limit exceeded on a WHERE IN query on a view
Date
Msg-id BAY176-W382A9DE827EBC8E602B7BBC5860@phx.gbl
Whole thread Raw
Responses Re: getting ERROR: stack depth limit exceeded on a WHERE IN query on a view
List pgsql-novice
Hi ,

I am trying to run the following query on a view that is basically composed of 3 table joins . The query includes a WHERE IN clause which searches for the list of pairs specified in the WHERE IN expression inside one of the underlying tables of the query and calculates the count of the matches. The query is similar to the following query:

       select count(*) from gui_die_summary where (x_coord, y_coord) in ((25,5),(41,13),(25,7),(28,3),(25,8),(34,7),(26,6),(21,10)); ,

only that the list of pairs specified in the in clause is pretty large - around 5000-4000 pairs and that's when I get the stack depth limit exceed error. the columns x_coord and y_coord are contained in the table device_info which is one of the tables used in the join . The database contains an index on device_info(x_coord,y_coord) . The query plan for the above query(and similarly for the query with a larger number of pairs in the  WHERE IN expression) does use that index :

      explain analyze select count(*) from gui_die_summary where (x_coord, y_coord) in ((25,5),(41,13),(25,7),(28,3),(25,8),(34,7),(26,6),(21,10));

                                                                                                                                                                                                          QUERY PLAN                        
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=2517.41..2517.42 rows=1 width=0) (actual time=33.006..33.006 rows=1 loops=1)
   ->  Sort  (cost=2517.25..2517.28 rows=10 width=82) (actual time=32.996..32.999 rows=21 loops=1)
         Sort Key: (CASE WHEN (diagnose_runlog.scandie IS TRUE) THEN 'yes'::text ELSE 'no'::text END), diagnose_runlog.num_total_suspects, ((((diagnose_runlog.total_tfsf)::double precision * 100::double precision) / (CASE WHEN (diagnose_runlog.num_simulated = 0) THEN diagnose_runlog.total_tfsf ELSE diagnose_runlog.num_simulated END)::double precision))
         Sort Method:  quicksort  Memory: 27kB
         ->  Hash Join  (cost=2408.43..2517.09 rows=10 width=82) (actual time=24.919..32.929 rows=21 loops=1)
               Hash Cond: (COALESCE(failset_scenarios.device_id, partition_runlog.device_id) = device_info.device_id)
               ->  Merge Full Join  (cost=2346.37..2432.98 rows=5818 width=49) (actual time=23.880..31.658 rows=5788 loops=1)
                     Merge Cond: ((failset_scenarios.scenario_id = partition_runlog.scenario_id) AND (failset_scenarios.device_id = partition_runlog.device_id))
                     ->  Sort  (cost=593.99..608.53 rows=5818 width=8) (actual time=3.475..4.083 rows=5788 loops=1)
                           Sort Key: failset_scenarios.scenario_id, failset_scenarios.device_id
                           Sort Method:  quicksort  Memory: 464kB
                           ->  Seq Scan on failset_scenarios  (cost=0.00..230.18 rows=5818 width=8) (actual time=0.004..1.866 rows=5788 loops=1)
                     ->  Sort  (cost=1752.38..1766.70 rows=5729 width=49) (actual time=20.397..21.086 rows=5729 loops=1)
                           Sort Key: partition_runlog.scenario_id, partition_runlog.device_id
                           Sort Method:  quicksort  Memory: 998kB
                           ->  Hash Join  (cost=649.90..1394.77 rows=5729 width=49) (actual time=4.923..13.704 rows=5729 loops=1)
                                 Hash Cond: (diagnose_runlog.part_id = partition_runlog.part_id)
                                 ->  Seq Scan on diagnose_runlog  (cost=0.00..630.29 rows=5729 width=45) (actual time=0.003..1.633 rows=5729 loops=1)
                                 ->  Hash  (cost=578.29..578.29 rows=5729 width=12) (actual time=4.906..4.906 rows=5729 loops=1)
                                       ->  Seq Scan on partition_runlog  (cost=0.00..578.29 rows=5729 width=12) (actual time=0.002..2.659 rows=5729 loops=1)
               ->  Hash  (cost=61.94..61.94 rows=10 width=37) (actual time=0.108..0.108 rows=21 loops=1)
                     ->  Bitmap Heap Scan on device_info  (cost=34.12..61.94 rows=10 width=37) (actual time=0.063..0.089 rows=21 loops=1)
                           Recheck Cond: (((x_coord = 25) AND (y_coord = 5)) OR ((x_coord = 41) AND (y_coord = 13)) OR ((x_coord = 25) AND (y_coord = 7)) OR ((x_coord = 28) AND (y_coord = 3)) OR ((x_coord = 25) AND (y_coord = 8)) OR ((x_coord = 34) AND (y_coord = 7)) OR ((x_coord = 26) AND (y_coord = 6)) OR ((x_coord = 21) AND (y_coord = 10)))
                           ->  BitmapOr  (cost=34.12..34.12 rows=10 width=0) (actual time=0.053..0.053 rows=0 loops=1)
                                 ->  Bitmap Index Scan on x_y_idx  (cost=0.00..4.26 rows=1 width=0) (actual time=0.020..0.020 rows=3 loops=1)
                                       Index Cond: ((x_coord = 25) AND (y_coord = 5))
                                 ->  Bitmap Index Scan on x_y_idx  (cost=0.00..4.26 rows=1 width=0) (actual time=0.005..0.005 rows=1 loops=1)
                                       Index Cond: ((x_coord = 41) AND (y_coord = 13))
                                 ->  Bitmap Index Scan on x_y_idx  (cost=0.00..4.26 rows=1 width=0) (actual time=0.005..0.005 rows=3 loops=1)
                                       Index Cond: ((x_coord = 25) AND (y_coord = 7))
                                 ->  Bitmap Index Scan on x_y_idx  (cost=0.00..4.27 rows=2 width=0) (actual time=0.005..0.005 rows=6 loops=1)
                                       Index Cond: ((x_coord = 28) AND (y_coord = 3))
                                 ->  Bitmap Index Scan on x_y_idx  (cost=0.00..4.26 rows=1 width=0) (actual time=0.003..0.003 rows=1 loops=1)
                                       Index Cond: ((x_coord = 25) AND (y_coord = 8))
                                 ->  Bitmap Index Scan on x_y_idx  (cost=0.00..4.26 rows=1 width=0) (actual time=0.005..0.005 rows=1 loops=1)
                                       Index Cond: ((x_coord = 34) AND (y_coord = 7))
                                 ->  Bitmap Index Scan on x_y_idx  (cost=0.00..4.26 rows=1 width=0) (actual time=0.004..0.004 rows=2 loops=1)
                                       Index Cond: ((x_coord = 26) AND (y_coord = 6))
                                 ->  Bitmap Index Scan on x_y_idx  (cost=0.00..4.26 rows=1 width=0) (actual time=0.005..0.005 rows=4 loops=1)
                                       Index Cond: ((x_coord = 21) AND (y_coord = 10))
 Total runtime: 33.196 ms
(41 rows)


However, when i do just a select(*) on the same view , with the same WHERE IN expression (with a large number of pairs), I do not get the stack depth limit exceeded error. Please help me understand the origin of this error and how can I change my query/schema in order to make such queries against the database.

Thanks
Aditya


pgsql-novice by date:

Previous
From: amul sul
Date:
Subject: SRF_RETURN_NEXT Error: rows returned by function are not all of the same row type
Next
From: Tom Lane
Date:
Subject: Re: getting ERROR: stack depth limit exceeded on a WHERE IN query on a view