Hi,

In my database I find that the explain program for the view (114
statements) is much longer than direct query that comprises the view
(89) and almost twice as long as doing the 2 separate queries that make
up the union in the view (39 + 30 = 69).

To explain more clearly what I mean, if I create a database as...

CREATE TABLE ta (a INTEGER NOT NULL, b VARCHAR(30));
CREATE TABLE tb (a INTEGER NOT NULL, b VARCHAR(30));
CREATE VIEW va AS
    SELECT a, b, 0 AS c FROM ta UNION SELECT a, b, 1 FROM tb;

And then run the explain statements...

EXPLAIN SELECT a, b, 0 AS c FROM ta;
EXPLAIN SELECT a, b, 1 AS c FROM tb;
EXPLAIN SELECT a, b, 0 AS c FROM ta UNION SELECT a, b, 1 FROM tb;
EXPLAIN SELECT * FROM va;

I get the results... 15, 15, 35, 45 (using sqlite 3.3.8)

So in this contrived example, we have an overhead of 5 statements for
the union, and 10 statements for using the view over issuing the direct
union query itself. Not a lot in this example but still indicative of
what I am seeing in my database.

I assume from this, that querying from a view is slower than querying
the tables directly or even just issuing the same query as the view
directly? Is it worth going back to issuing direct queries? The
advantage of the view is simplicity of course.

Regards,
Brodie

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to