Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Q: using indexes in select 1

Status
Not open for further replies.

thedaver

IS-IT--Management
Jul 12, 2001
2,741
US
I have two tables.
=====================================
create table company (
co_id int not null auto_increment primary key,
co_name char(80) not null);

create table user (
us_id int not null auto_increment primary key,
us_co_id int not null,
us_name char(80) not null,
index idx_us_co_id us_co_id());
=====================================

stupid question: I want to leverage the index to select users who are associated with the company. Do I have to reference "idx_us_co_id" or "us_co_id" from table 'user' in order to get the benefit of indexing. In short, which is (theoretically) faster because it is using the index???

STATEMENT 1:
select * from user u, company c where u.idx_us_co_id=c.co_id and u.us_id=5;

STATEMENT 2:
select * from user u, company c where u.us_co_id=c.co_id and u.us_id=5;

Do I even need the index in table 'user' in this use context?




Surfinbox.com Business Internet Services - National Dialup, DSL, T-1 and more.
 
OK, good, but do I refer to the INDEX name or the column name in the where clause?!?!!? I am not using compound column indices (ie index a_and_b(a,b)).

Surfinbox.com Business Internet Services - National Dialup, DSL, T-1 and more.
 
hi sleipnir214
Though not related to the tread but what is 'automagically' ? I have come across at no of places but never fighred what is the diff between this and automatically



[ponder]
----------------
ur feedback is a very welcome desire
 
r937 has it right.

The definition probably has its roots in Arthur C. Clarke's Third Law of Technology, which states, "Any sufficiently advanced technology is indistinguishable from magic."



If you want to understand how MySQL uses indexes, go to the horse's mouth:
Want the best answers? Ask the best questions: TANSTAAFL!!
 
thanks to both of you sleipnir214 and r937.
And this time i am careful to write complete you for u. I write in short because i have to pay for the internet account charge for the time i am on + the phone call which has 2 min as one unit (+ the taxes on it. Presently 8% which is to become 12% verry shortly)



[ponder]
----------------
ur feedback is a very welcome desire
 
i understand about connect time

the answer is shorter sentences

fewer words, clearer ideas

try it

it's easy

:)



rudy
SQL Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top