Search notes:

Perl module DBD::SQLite - explaining a query plan

#!/usr/bin/perl
use warnings;
use strict;
use DBI;

my $db = 'explain_query_plan.db';

unlink $db if -f $db;
my $dbh = DBI->connect("dbi:SQLite:dbname=$db") or die "Could not create $db";

$dbh->do(q{
  create table p (
    id   int primary key,
    col  text
  )
}) or die;

$dbh->do(q{
  create table c (
    id    int primary key,
    id_p  int references p,
    col   text
  )
}) or die;

$dbh->do(q{
  create index ix_p on p (col)
}) or die;

my $sth = $dbh->prepare(q{
  explain query plan
  select
    c.col col_c
  from
    p                  join
    c on p.id = c.id_p
  where
    c.col = 'foo'
 }
) or die;

$sth->execute;

while (my @r = $sth->fetchrow_array) {
  printf "%2d %2d %2d %s\n", @r;
}
Github repository PerlModules, path: /DBD/SQLite/explain_query_plan.pl

See also

DBD::SQLite
SQLite: explain query plan

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758204645, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Perl/modules/DBD/SQLite/explain_query_plan(86): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78