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!

how to inform the indexs to be used in a query

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
How's the SQL sintaxe using index? I'm using 3 tables in my query and it's awfully slow. How can I inform the index to be used in such query?

Here is the query:
select distinct r.nmfuncio as nome,
r.dsendfun as endereco,
r.dscomple as Complemeto,
rhs.GS125.DSELEMEN as Bairro,
' ' as cidade,
' ' as estado,
r.nrtelefo as telefone,
r.dsponref as pontoreferencia,
' 'as empresa,
r.nrcarpon as matricula,
d.sgccusto as centrocusto
from rhs.rh002 r, linc.dbtab_tcust d, rhs.gs125
where rhs.gs125.CDEMPRES = 01 and
r.cdcencus = d.cdcustomag AND
r.cdsitatu = 1 and
rhs.gs125.cdtabela = 6289 and
rhs.gs125.CDELEMTO = cdbairro

order by nome

The indexs I wanna use are the following ones:
rhs.fkeyrh002 (KEYRH002) or
rhs.rh00201(CDEMPRES, CDFILIAL, NMFUNCIO, NRCARPON) or
rhs.00204(NRCARPON).
 
You can try this:

select /*+ INDEX(rhs.fkeyrh002)*/
distinct r.nmfuncio as nome,
r.dsendfun as endereco,
r.dscomple as Complemeto,
rhs.GS125.DSELEMEN as Bairro,
' ' as cidade,
' ' as estado,
r.nrtelefo as telefone,
r.dsponref as pontoreferencia,
' 'as empresa,
r.nrcarpon as matricula,
d.sgccusto as centrocusto
from rhs.rh002 r, linc.dbtab_tcust d, rhs.gs125
where rhs.gs125.CDEMPRES = 01 and
r.cdcencus = d.cdcustomag AND
r.cdsitatu = 1 and
rhs.gs125.cdtabela = 6289 and
rhs.gs125.CDELEMTO = cdbairro
order by nome

The HINT syntax is explained in detail in SQL refernece.

Gius
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top