Subject | Re: How to optimize view to work faster |
---|---|
Author | Svein Erling Tysvær |
Post date | 2007-12-11T14:23:25Z |
Why do it so complicated?
SELECT X.ID, X.SESIJA, X.UIP, X.TIP, X.OBJEKAT, X.KOMITENTI,
X.KOMOBJEKTI, X.KOMITENTIP, X.BROJ, X.BROJS, X.DATUM,
SUM(Y.NVVREDNOST) AS NVVREDNOST, SUM(Y.SVREDNOST) AS SVREDNOST,
SUM(Y.RVREDNOST) AS RVREDNOST (I didn't bother to write more)
FROM ROBFAKTURA X
LEFT OUTER JOIN ROBFAKTURAS Y ON Y.ROBFAKTURA = X.ID
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
Now, if there are lots of records in the tables (at least in Y), then
of course it will be time consuming.
HTH,
Set
SELECT X.ID, X.SESIJA, X.UIP, X.TIP, X.OBJEKAT, X.KOMITENTI,
X.KOMOBJEKTI, X.KOMITENTIP, X.BROJ, X.BROJS, X.DATUM,
SUM(Y.NVVREDNOST) AS NVVREDNOST, SUM(Y.SVREDNOST) AS SVREDNOST,
SUM(Y.RVREDNOST) AS RVREDNOST (I didn't bother to write more)
FROM ROBFAKTURA X
LEFT OUTER JOIN ROBFAKTURAS Y ON Y.ROBFAKTURA = X.ID
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
Now, if there are lots of records in the tables (at least in Y), then
of course it will be time consuming.
HTH,
Set
--- In firebird-support@yahoogroups.com, "Sasa Mihajlovic" wrote:
> Hi,
>
> I have two tables robfaktura (invoice header) and robfakturas
> (invoice items), and wiev based on these two tables:
>
> SELECT Z.ID, Z.SESIJA, Z.UIP, Z.TIP, Z.OBJEKAT, Z.KOMITENTI,
> Z.KOMOBJEKTI, Z.KOMITENTIP, Z.BROJ, Z.BROJS, Z.DATUM,
> Q.NVREDNOST, Q.SVREDNOST, Q.RVREDNOST, Q.OVREDNOST,
> Q.PVREDNOST, Q.KVREDNOST, Q.NVVREDNOST, Q.UVREDNOST
> FROM ROBFAKTURA Z
> JOIN ( SELECT X. ID, SUM(Y.NVREDNOST) AS NVREDNOST, SUM
(Y.SVREDNOST)
> AS SVREDNOST, SUM(Y.RVREDNOST) AS RVREDNOST, SUM(Y.OVREDNOST) AS
> OVREDNOST,
> SUM(Y.PVREDNOST) AS PVREDNOST, SUM(Y.KVREDNOST) AS
> KVREDNOST, SUM(Y.NVVREDNOST) AS NVVREDNOST, SUM(Y.KVREDNOST -
> X.POPUSTVR - X.AVANS1 - X.AVANS2 - X.AVANS3) AS UVREDNOST
> FROM ROBFAKTURA X
> LEFT OUTER JOIN ROBFAKTURAS Y ON Y.ROBFAKTURA = X.ID
> GROUP BY X.ID) Q ON Q.ID = Z.ID
>
> I have one simple question for Firebird experts, how to optimize
this
> viev (sql statement) if header table have more then milion records
> and everytime when I call this view I must wait about 5-10 minutes
> even I get empty table as resultset?
> Or someone have smarter solution than mine?
>
> Thnaks in advance...