2017-09-15 13 views
1


오라클의 sdo_contains 공간 연산자를 사용하려고하는데, 유니언 테이블에서 사용할 때 실제로 작동하지 않는 것 같습니다. 아래 코드는 2 분에서 실행,하지만 당신은 모든 소스 테이블의 공간 연산자를 복제 할 필요가 : 나는 그것을 간단하게하고 싶었
오라클의 SDO_CONTAINS가 유니언트 테이블에서 공간 인덱스를 사용하지 않습니까?

SELECT -- works 
    x.code, 
    count(x.my_id) cnt 
FROM (select 
     c.code, 
     t.my_id 
     from my_poi_table_1 t,my_shape c 
     WHERE SDO_contains(c.shape, 
        sdo_geometry(2001,null,SDO_POINT_type(t.latitude, t.longitude,null),null,null) 
        ) = 'TRUE' 
     union all 
     select 
     c.code, 
     t.my_id 
     from my_poi_table_2 t,my_shape c 
     where SDO_contains(c.shape, 
        sdo_geometry(2001,null,SDO_POINT_type(t.lat, t.lng,null),null,null) 
        ) = 'TRUE' 
    ) x 
group by x.code 

, 그래서 한 번만 먼저 포인트를 만들려고하고, 그 위에 sdo_contains를 사용하지만,이 공간 인덱스 사용하지 있기 때문에 그것은 더 다음 25 분 동안 실행중인 :

SELECT -- does not work 
    c.code, 
    count(x.my_id) cnt 
FROM my_shape c, 
    (select 
     my_id, 
     sdo_geometry(2001,null,SDO_POINT_type(latitude, longitude,null),null,null) point 
     from my_poi_table_1 t 
     union all 
     select 
     my_id2, 
     sdo_geometry(2001,null,SDO_POINT_type(lat, lng,null),null,null) point 
     from my_poi_table_2 t 
    ) x 
WHERE SDO_contains(c.shape, 
        x.point 
        ) = 'TRUE' 
group by c.code 

을 포함 할 필요없이 여러 테이블의 결과에 sdo_contains를 사용하는 방법이 있나요을 선택 몇 번?
오라클 : 12.1.0.2

답변

1

sdo_contains이 (효율적) 부속 선택에서 읽을 수 있다는 것 :

를 : 오라클 그 부분에 대한 공간 인덱스를 사용하지 않습니다 나는 부속 선택에 포이 테이블 중 하나를 넣을 경우
SELECT -- does not work 
    x.code, 
    count(x.my_id) cnt 
FROM (select --+ ordered index(c,INDEX_NAME) 
     c.code, 
     t.my_id 
     from my_shape c,(select t.*,rownum rn from my_poi_table_1 t) t 
     WHERE SDO_contains(c.shape, 
        sdo_geometry(2001,null,SDO_POINT_type(t.latitude, t.longitude,null),null,null) 
        ) = 'TRUE' 
     union all 
     select 
     c.code, 
     t.my_id 
     from my_poi_table_2 t,my_shape c 
     where SDO_contains(c.shape, 
        sdo_geometry(2001,null,SDO_POINT_type(t.lat, t.lng,null),null,null) 
        ) = 'TRUE' 
    ) x 
group by x.code