0

In my SQL-Server 2008 R2 i have a SQL query:

SELECT
IceCrossing.WaterwayName as WaterWayName,
IceCrossing.Segment_ID as Segment_ID,
the_geom = Track.Track
FROM dbo.IceCrossing
LEFT JOIN Track ON IceCrossing.Segment_ID=Track.Segment_ID

There i want to select all rows from IceCrossing and if in Track exists row with same Segment_ID show it in result. And there is problem with JOIN. Becouse its query works 4-5 seconds for return me my 260 rows. I was tried to change it:

SELECT
IceCrossing.WaterwayName as WaterWayName,
IceCrossing.Segment_ID as Segment_ID,
the_geom = Track.Track
FROM dbo.Track
RIGHT JOIN IceCrossing ON Track.Segment_ID=IceCrossing.Segment_ID

But same time.
Its possible to make it faster without make a any things with data base and table structures?

UPDATE

More info.
Track - 209 rows.
IceCrossing - 259 rows. Segment_ID type - [uniqueidentifier]
How to know about indexes on this?

UPDATE2

How i understand my problem in the the_geom field. Becouse query:

    SELECT
IceCrossing.WaterwayName as WaterWayName,
IceCrossing.Segment_ID as Segment_ID,
FROM dbo.IceCrossing
LEFT JOIN Track ON IceCrossing.Segment_ID=Track.Segment_ID

Works within a second.
the_geom type - geometry its like a very long string.
What can i do in this case?

4

2 回答 2

3

加入很好。您可能需要一个索引,无论是 onTrack(Segment_ID)还是IceCrossing(Segment_ID).

有了这么多的数据,我很惊讶查询可能需要这么长时间。您是否多次运行查询并获得一致的结果?服务器上还有其他东西在运行吗?

left outer join和之间的性能没有区别right outer join。他们做同样的事情。

于 2013-07-28T16:34:25.097 回答
1

你试过简单select * from Trackselect * from IceCrossing?如果您的某一列中有大量数据(例如,varbinary(max)),则可能不是查询速度慢,而是在客户端接收所有数据。

试试那个查询

select
    I.Segment_ID,
    T.Segment_ID
from dbo.IceCrossing as I
    left outer join Track as T on T.Segment_ID = I.Segment_ID

它执行多长时间?

于 2013-07-28T16:43:46.640 回答