Subject | Re: slow left join on a view. |
---|---|
Author | samysong2002 |
Post date | 2002-11-20T20:04:02Z |
It's alway's a issue, when we do a left join on a VIEW it doesn't use
the index on the table the VIEW is base on.
Ex.
contact table
contact_code int Unique Index(contact_code)
name
adress....
city_id Unique Index(city_id)
....
city table
city_id Unique Index(city_id)
city name
province
country
Contact_view
create view contacts_view
(name,adress,city_name,province,country)
as
select contact.name,contact.adress,city.city_name,city.province,
city.country from contact contact
left join city on city.city_id = contact.city_id
======
Room Table
room_number Unique index
owner
if I do a :
select * from rooms rooms
left join contact_view on contact_view.contact_code = rooms.owner
This select will take a lot more time then
select * from rooms rooms
left join contact on contact.contact_code = rooms.owner
left join city on city.city_id = contact.city_id
The reason why it doing this, it's not using the contact index when
we use the VIEW but it use it when we use the tables directly.
That's may be not a bug, but it's bugging me.:)
Samy
the index on the table the VIEW is base on.
Ex.
contact table
contact_code int Unique Index(contact_code)
name
adress....
city_id Unique Index(city_id)
....
city table
city_id Unique Index(city_id)
city name
province
country
Contact_view
create view contacts_view
(name,adress,city_name,province,country)
as
select contact.name,contact.adress,city.city_name,city.province,
city.country from contact contact
left join city on city.city_id = contact.city_id
======
Room Table
room_number Unique index
owner
if I do a :
select * from rooms rooms
left join contact_view on contact_view.contact_code = rooms.owner
This select will take a lot more time then
select * from rooms rooms
left join contact on contact.contact_code = rooms.owner
left join city on city.city_id = contact.city_id
The reason why it doing this, it's not using the contact index when
we use the VIEW but it use it when we use the tables directly.
That's may be not a bug, but it's bugging me.:)
Samy