I have this query that is the result of a third-party software:
SELECT DISTINCT D.SucursalTiendas FROM (((HPapiro A
INNER JOIN DGrupo B ON A.CnCveGrupo = B.CnCveGrupo)
INNER JOIN DPapiroNiveles C ON A.CnCveCompania = C.CnCveCompania AND A.Nivel1 = C.CnCveNivelCuentas1 AND A.Nivel2 = C.CnCveNivelCuentas2)
LEFT OUTER JOIN Papiro D ON A.CnCveSucursal = D.CveSucursalTiendas)
The table HPapiro has 2 indexes: one clustered (which is the primary key) and one non-clustered (who has the fields to join DPapiroNiveles) The rest of the tables have only the Primary key index.
The execution plan shows that it consumes 23% of the process by making an index scan on the non-clustered index in HPapiro. And the scan for the primary key takes only 1% of the process.
If I delete the non-clustered index, the execution plan shows a 37% of usuage by scanning the clustered index on HPapiro (the primary key).
I want to improve the time of this query. It takes the same time if I run the query with or without the non-clustered index. How can I can improve the time of this query using indexes?
Thanks,
SELECT DISTINCT D.SucursalTiendas FROM (((HPapiro A
INNER JOIN DGrupo B ON A.CnCveGrupo = B.CnCveGrupo)
INNER JOIN DPapiroNiveles C ON A.CnCveCompania = C.CnCveCompania AND A.Nivel1 = C.CnCveNivelCuentas1 AND A.Nivel2 = C.CnCveNivelCuentas2)
LEFT OUTER JOIN Papiro D ON A.CnCveSucursal = D.CveSucursalTiendas)
The table HPapiro has 2 indexes: one clustered (which is the primary key) and one non-clustered (who has the fields to join DPapiroNiveles) The rest of the tables have only the Primary key index.
The execution plan shows that it consumes 23% of the process by making an index scan on the non-clustered index in HPapiro. And the scan for the primary key takes only 1% of the process.
If I delete the non-clustered index, the execution plan shows a 37% of usuage by scanning the clustered index on HPapiro (the primary key).
I want to improve the time of this query. It takes the same time if I run the query with or without the non-clustered index. How can I can improve the time of this query using indexes?
Thanks,