Hello everyone!
I have a Firebird database, which let's say has Tables A and B which look like this:
TableA
TableB's Id | SomeNumber | OtherNumber | ComputedByField | OtherIntField
1 5 200 SomeNumber*OtherNumber 10
1 2 70 ... 20
TableB
Id | Sum | Sum
1 Sum of OtherIntFIeld Sum of ComputedByField
where TableA'sId = TableB's Id
But now that TableB is getting populated (it's at 2k rows) accessing it becomes also slow due to that computation.
So my question is : Should I drop TableA's computedby
field and add it straight into TableB, and when new TableA rows are added to modify the Corresponding row manually? (This should be faster, but I don't really like it)
Edit: The performance issue comes from the fact that there are two computedby
fields which do exactly the same query over TableA but return different fields. I guess that is the part which needs optimization.
Edit2: The rows are computed as follows
TABLEB_FIELD_X COMPUTED BY ((
select SUM(TableA.FieldX) from TableA
where TableA.FAT_ID = TableB.ID
))
TABLEB_FIELD_Y COMPUTED BY ((
select SUM(TableA.FieldY) from TableA
where TableA.FAT_ID = TableB.ID
))
The main issue I believe comes from the fact these two independent fields query the same rows from TableA they just get a different field as result.