Views and performance

Hi,

I wonder if I have a “view A”, that select from a “table B”.

If the computation of A is quite computational intensive. When I update a small portion of B, will the entire “view A” be recomputed, or only the part that have changed will be recomputed?

Yes, I know view is only computed when it was referenced. But I am also interested if “partial” computation exist.

Thanks

Gary

No, I don’t think there is any “partial recomputation” there. The definition of A will be reused to refresh the snapshot for A when it’s first referenced after B is modified.

Hi 
by accessing a part of the view, the whole view is calculated. Here you can see it:

q)a:(a:1 2 3;b:2 3 4;c:5 6 7)

q)logplus:{0N!(x;y); x+y}

q)v::update ab:logplus[a;b], bc:logplus[b;c] from a

q)select a from v where a=1;  /output logged as the fields are generated (although they are not used!)

(1 2 3;2 3 4)

(2 3 4;4 1 1)

q)select from v where a=1;  /no output!  fields are cached

q)update c:4 from `a where a=1  

`a

q)select from v where a=1;   /all fields are reevaluated, KDB seems to only invalidate the complete table

(1 2 3;2 3 4)

(2 3 4;4 1 1)

Markus

http://code.kx.com/wiki/Views

if a view is invalidated, the view expression is executed the next time the view is used. You can decide what the view expression does in terms of what to recalc.

although .z.vs is triggered each time a global is amended, it’s a bit messy trying to keep track of what has changed in the view, especially since when the view does update it should not change globals to reset the change list.

However, you can calc what changed since last time in the view itself. e.g.

q)a:til 10
q)v::$[(::)~v;a;{0N!where x<>v;a}a]
q)v
0 1 2 3 4 5 6 7 8 9
q)a[3]:0
q)v
,3
0 1 2 0 4 5 6 7 8 9