Sunday, May 29, 2011

Intension and Extension?

I wrote the following code.

foreach(var e1 in
  from table_1
  where table_1.field_1 == 3
  select table_1) {

  foreach(var e2 in
    from table_2
    where table_2.field_2 == e1.field_1a
    select table_2) {

    foreach(var e3 in
      from table_3
      where table_3.field_3 == e2.field_2b
      select table_3) {
      ...
    }
  }
}

But the query of that code can be written in SQL as following:

SELECT *
FROM TABLE_3,
  (SELECT *
  FROM TABLE_2,
    (SELECT *
    FROM TABLE_1
    WHERE TABLE_1.FIELD_1 = 3
    ) X
  WHERE TABLE_2.FIELD_2 = X.FIELD_1A
  ) Y
WHERE TABLE_3.FIELD_3 = Y.FIELD_2B

In the former code, the loop is expanded inside. But the SQL is expanded outside.
It is interesting but I do not know that it is significant.

No comments:

Post a Comment