Paolo Bolzoni wrote:
> sqlite> explain query plan SELECT id FROM tour LIMIT 1;
> 0|0|0|SCAN TABLE tour USING COVERING INDEX tour_unsorted_path_idx
>                                                     (~1000000 rows)
>
> I am not still sure I understand completely the output of explain
> query plan.

It means that SQLite estimates that the table (or its index) contains
about 1000000 rows.

The LIMIT clause is *not* used for this estimate.

> To get this simple result, sqlite3 actually scans the whole
> table?

No.  Without the LIMIT, the query would scan the entire index.  With the
LIMIT, the scan is stopped after the first row.

> I just have a question about query written in the begin, in my
> application I use it to know if a table is empty. I execute it
> and just use sqlite3_step return value. Errors a part, if it is
> SQLITE_DONE the table is empty, if it is SQLITE_ROW it is not.

This is more a documentation than an optimization improvement, but if
you are not interested in the value of any particular column, you should
not request it in the first place; i.e., use something like:
  SELECT 0 FROM tour LIMIT 1;


Regards,
Clemens
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to