<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Poor performance of spatial query in view with multiple geometry type unioned in Developers Questions</title>
    <link>https://community.esri.com/t5/developers-questions/poor-performance-of-spatial-query-in-view-with/m-p/41549#M224</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using Arcgis SDE 10 to export our geographic data to the Oracle 11g database, and the spatial column are saved using the `St_Geometry` type.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And we have almost 10 + tables with points, lines, and polygons.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However we have to query the data despite of their geometry type, so I create a view which union all the required table and columns to the view, like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;create or replace view MyView as
&amp;nbsp; select objectid,shape,name,address, 'FeaturePY' as table_name from FeaturePY
union all
&amp;nbsp; select objectid,shape,name,address, 'FeatureLN' as table_name from FeatureLN
union all
&amp;nbsp; select objectid,shape,name,address, 'FeaturePY' as table_name from FeaturePY
........&lt;/PRE&gt;&lt;P&gt;Everything works well unless I try to query the data by some spatial , for example, I want to query data inside the bounding box of&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="line-height: 1.5;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="line-height: 1.5;"&gt;20.22774247419824,30.168182996158205,20.29657868635644 30.21127000177344)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;and make a pagination, I use the following two sqls:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) for data&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;select * from ( select name,st_astext(shape) as shape from MyView h where ST_Intersects(h.shape, st_geometry('POLYGON ((20.22774247419824 30.168182996158205, 20.29657868635644 30.168182996158205, 20.29657868635644 30.21127000177344, 20.22774247419824 30.21127000177344, 20.22774247419824 30.168182996158205))',3)) = 1 ) where rownum &amp;lt;= 10&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) for total count:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;select count(shape) from MyView h where ST_Intersects(h.shape, st_geometry('POLYGON ((20.22774247419824 30.168182996158205, 20.29657868635644 30.168182996158205, 20.29657868635644 30.21127000177344, 20.22774247419824 30.21127000177344, 20.22774247419824 30.168182996158205))',3)) = 1&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However I found that the first sql will cost almost 30 seconds to get the data, and the second sql will take almost 6 minutes to get the count which is unacceptable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And I have tried to use a different spatial function `ST_ENVINTERSECTS` to replace the `ST_Intersects`, but I can not get any improvement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is my current environment:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Dbserver: Windows server 2008 x64
Arcgis SDE 10 x64 with service pack5 installed.
Oracle 11gR2 x64
Records in the view: almost 150,000&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not sure what's the problem, any suggestion to fix this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 21:36:39 GMT</pubDate>
    <dc:creator>kkkk1</dc:creator>
    <dc:date>2021-12-10T21:36:39Z</dc:date>
    <item>
      <title>Poor performance of spatial query in view with multiple geometry type unioned</title>
      <link>https://community.esri.com/t5/developers-questions/poor-performance-of-spatial-query-in-view-with/m-p/41549#M224</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using Arcgis SDE 10 to export our geographic data to the Oracle 11g database, and the spatial column are saved using the `St_Geometry` type.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And we have almost 10 + tables with points, lines, and polygons.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However we have to query the data despite of their geometry type, so I create a view which union all the required table and columns to the view, like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;create or replace view MyView as
&amp;nbsp; select objectid,shape,name,address, 'FeaturePY' as table_name from FeaturePY
union all
&amp;nbsp; select objectid,shape,name,address, 'FeatureLN' as table_name from FeatureLN
union all
&amp;nbsp; select objectid,shape,name,address, 'FeaturePY' as table_name from FeaturePY
........&lt;/PRE&gt;&lt;P&gt;Everything works well unless I try to query the data by some spatial , for example, I want to query data inside the bounding box of&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="line-height: 1.5;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="line-height: 1.5;"&gt;20.22774247419824,30.168182996158205,20.29657868635644 30.21127000177344)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;and make a pagination, I use the following two sqls:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) for data&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;select * from ( select name,st_astext(shape) as shape from MyView h where ST_Intersects(h.shape, st_geometry('POLYGON ((20.22774247419824 30.168182996158205, 20.29657868635644 30.168182996158205, 20.29657868635644 30.21127000177344, 20.22774247419824 30.21127000177344, 20.22774247419824 30.168182996158205))',3)) = 1 ) where rownum &amp;lt;= 10&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) for total count:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;select count(shape) from MyView h where ST_Intersects(h.shape, st_geometry('POLYGON ((20.22774247419824 30.168182996158205, 20.29657868635644 30.168182996158205, 20.29657868635644 30.21127000177344, 20.22774247419824 30.21127000177344, 20.22774247419824 30.168182996158205))',3)) = 1&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However I found that the first sql will cost almost 30 seconds to get the data, and the second sql will take almost 6 minutes to get the count which is unacceptable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And I have tried to use a different spatial function `ST_ENVINTERSECTS` to replace the `ST_Intersects`, but I can not get any improvement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is my current environment:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Dbserver: Windows server 2008 x64
Arcgis SDE 10 x64 with service pack5 installed.
Oracle 11gR2 x64
Records in the view: almost 150,000&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not sure what's the problem, any suggestion to fix this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:36:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/poor-performance-of-spatial-query-in-view-with/m-p/41549#M224</guid>
      <dc:creator>kkkk1</dc:creator>
      <dc:date>2021-12-10T21:36:39Z</dc:date>
    </item>
  </channel>
</rss>

