Re: views of binary operations

From: Marshall <marshall.spight_at_gmail.com>
Date: 17 Jul 2006 22:02:37 -0700
Message-ID: <1153198957.487118.243080_at_h48g2000cwc.googlegroups.com>


Bob Badour wrote:
> Marshall wrote:
>
> > Consider named views of binary operations on relations.
> >
> > Given a relational operator "op" and relation variables A and B,
> > and a declaration of:
> >
> > r = A op B
> >
> > the language evaluates the expression "A op B" and assigns the
> > result to r.
> >
> > However, if we declare this as a view, we do not evaluate A op B
> > at the time of the declaration, but instead (re)evaluate A op B each
> > time we make reference to r in later expressions.
> >
> > r = view(A op B)
> >
> > Is it the case that we want exactly the above, or might we
> > want a more fine-grained control? Might we ever want
> >
> > r = A op view(B)
> >
> > In other words, the value of A at the time of the declaration and
> > value of B at the time of evaluations of r? In which case, we
> > then have four possibilities:
> >
> > r = A op B
> > r = view(A) op B
> > r = A op view(B)
> > r = view(A) op view(B)
> >
> > (Actual evaluation of the expression is deferred if either of
> > the operands is a view.)
> >
> > In other words, when we have a view of a binary relation operation,
> > are we necessarily creating a view of the entire expression, or are
> > we making views of the operands?
> >
> > (I am asking in the theoretical sense, and not about SQL per se,
> > although if current practice in SQL sheds light on the question,
> > I am interested in that as well.)
>
> I cannot make sense of what you are asking. Are you confusing views and
> snapshots by any chance?

It's possible. I'm quite green about both. But I believe I have some handle on the two concepts as immediate vs. delayed evaluation.

If we have a relation variable V, and assign its current value to R, would that not be a snapshot? The usual semantics of assignment would indicate that even if we later changed the value of V, the value of R would remain as it was upon creation/declaration.

roughly:

V = { (a=1), (a=2) };
R = V;
insert into V (a) values (3);

R and V are now unequal, with R having two elements, (a=1) and (a=2).

We could call that a snapshot, right? It is simple assignment.

On the other hand, if we declare R as a (identity) view onto V:

V = { (a=1), (a=2) };
R = view(V);
insert into V (a) values (3);

then we would expect after the above code, R would have the value { (a=1), (a=2), (a=3) }

Within a single scope, identity views are pointless; you can just use the original variable instead. However there might be a difference crossing an abstraction boundary. I don't recall any discussions in the past about the behavior of views when used as parameters. (Come to think of it, I don't recall any discussions of parameter evaluation strategies at all.)

I could imagine some potential uses to passing views as views, (in other words, by reference) rather than by value.

Views have something in common with lazy evaluation. However they are different at least insofar as lazy evaluation is deferred but executed at most once, whereas views are re-evaluated at each use.

Anyway, I'm drifting a bit at this point; I've had little sleep the last couple of days and might be simply raving by now.

Marshall Received on Tue Jul 18 2006 - 07:02:37 CEST

Original text of this message