<div dir="ltr">  Hi Team,<br><br>Thanks for your support.<br><br>Could someone please suggest on the below query.<br><br>One of the query which was created on GIS data is taking a long time and even it is not taking the index as well. I have included all the required details for reference.<br><br><font color="#ff0000">Database Stack:</font><br>===============<br>PostgreSQL : 9.5.15<br>Postgis: 2.2.7<br><br><font color="#ff0000">Table Structure:</font><br>===================<br><br>ALTER TABLE SCHEMA.TABLE_NAME ADD COLUMN parental_path text;<br><br><font color="#ff0000">Created Indexes on column parental_path:</font><br>=================================<br><br>CREATE INDEX cable_pair_parental_path_idx<br>  ON SCHEMA.TABLE_NAME<br>  USING btree<br>  (md5(parental_path) COLLATE pg_catalog."default");<br>  <br>CREATE INDEX cable_pair_parental_path_idx_fulltext<br>  ON SCHEMA.TABLE_NAME<br>  USING gist<br>  (parental_path COLLATE pg_catalog."default");<br>  <br><font color="#ff0000">Sample data in "parental_path" column:</font><br>======================================<br>  <br>'route--2309421/2951584/3373649/2511322/1915187/2696397/2623291/2420708/2144348/2294454,circuit--88458/88460,sheath--8874'<br><br><font color="#ff0000">Actual Query:</font><br>=============<br><br>SELECT seq_no + 1 FROM SCHEMA.TABLE_NAME WHERE (parental_path LIKE '%,sheath--' || cable_seq_id || ',%' OR parental_path LIKE 'sheath--' || cable_seq_id || ',%' OR parental_path LIKE '%,sheath--' || cable_seq_id OR parental_path = 'sheath--' || cable_seq_id) ORDER BY seq_no DESC LIMIT 1;<br><br><font color="#ff0000">Explain Plan:</font><br>=============<br><br>Limit  (cost=108111.60..108111.61 rows=1 width=4) (actual time=4597.605..4597.605 rows=0 loops=1)<br>        Output: ((seq_no + 1)), seq_no<br>       Buffers: shared hit=2967 read=69606 dirtied=1<br>        ->  Sort  (cost=108111.60..108113.09 rows=595 width=4) (actual time=4597.603..4597.603 rows=0 loops=1)<br>                Output: ((seq_no + 1)), seq_no<br>            Sort Key: TABLE_NAME.seq_no DESC<br>          Sort Method: quicksort  Memory: 25kB<br>             Buffers: shared hit=2967 read=69606 dirtied=1<br>             ->  <b><font color="#ff0000">Seq Scan on SCHEMA.TABLE_NAME  (cost=0.00..108108.63 rows=595 width=4) (actual time=4597.595..4597.595 rows=0 loops=1)</font></b><br>                   Output: (seq_no + 1), seq_no<br>                   <font color="#ff0000">Filter: ((TABLE_NAME.parental_path ~~ '%,sheath--64690,%'::text) OR (TABLE_NAME.parental_path ~~ 'sheath--64690,%'::text) OR (TABLE_NAME.parental_path ~~ '%,sheath--64690'::text) OR (TABLE_NAME.parental_path = 'sheath--64690'::text))</font><br>                   Rows Removed by Filter: 1930188<br>                Buffers: shared hit=2967 read=69606 dirtied=1<br><div><br></div><div>Please share your suggestion.</div><div>Thanks & Regards,</div><div>PostgAnn.</div></div>