Hi,
I have the followin relation ships
DATDECRESP->DATDECOP->DATDEC->DATDCECL
Now
I want to retrieve a set of records using Aureluis with the following
code(Also have tested using SubCriteria) with same results:
AManager.Find<TXDATDECL>
.CreateAlias('IDDATDEC', 'D')
.CreateAlias('D.IDDATDECOP', 'O')
.CreateAlias('O.Respuesta', 'R')
.Add(Linq['D.ID'] = Linq['IDDATDEC'])
.Add(Linq['O.ID'] = Linq['D.IDDATDECOP'])
.Add(Linq['R.IDDATDECOP'] = Linq['O.ID'])
.Add(Linq['R.IDDECLARACIONREGISTRADA'] = ARegistro)
.List;
It generates the following SQL:
SELECT A.ID AS A_ID, ... FROM DATDECL A
LEFT JOIN DATDEC B ON (B.ID = A.IDDATDEC)
LEFT JOIN DATDECOP C ON (C.ID = B.IDDATDECOP)
LEFT JOIN DATDECRESP D ON (D.IDDATDECOP = C.ID)
WHERE B.ID = A.IDDATDEC AND
C.ID = B.IDDATDECOP AND
D.IDDATDECOP = C.ID AND
D.IDDECLARACIONREGISTRADA = :p_0
The query takes 2 minutes to complete, checking the firebird plan shows the following:
PLAN JOIN (JOIN (JOIN (A NATURAL, B INDEX (PK_DATDEC)), C INDEX (PK_DATDECOP)), D INDEX (DATDECOP_DATDECRESP))
I will search for records on DATDECL in storage order making it ineficcient.
Now I have modified the above query with classic sql with no joins to the following:
SELECT A.ID AS A_ID, ... FROM DATDECL A, DATDEC B, DATDECOP C, DATDECRESP D
WHERE B.ID = A.IDDATDEC AND
C.ID = B.IDDATDECOP AND
D.IDDATDECOP = C.ID AND
D.IDDECLARACIONREGISTRADA = :p_0
the query take less than one second to complete and firebird now uses the following plan:
PLAN
JOIN (D INDEX (U_DATDECRESP_1), C INDEX (PK_DATDECOP), B INDEX
(DATDECOP_DATDEC), A INDEX (DATDEC_DATDECL)). using index on all tables.
how
I can make Aurelius genetares more simple and efficent queryes like the
above or should I have to change the Auelius search to diffetent
aproach.
Thanks in advance,
Omar Zelaya