CL-USER> (asdf:oos 'asdf:load-op :cl-perec-test.postgresql)
; loading system definition from
; /home/levy/workspace/perec/cl-perec-test.postgresql.asd into
; #<PACKAGE "ASDF0">
; registering #<SYSTEM :CL-PEREC-TEST.POSTGRESQL {10084CB601}> as
; CL-PEREC-TEST.POSTGRESQL
; loading system definition from
; /home/levy/workspace/perec/cl-perec-test.asd into #<PACKAGE "ASDF0">
; registering #<SYSTEM :CL-PEREC-TEST {10089BD7A1}> as CL-PEREC-TEST
WARNING:
   Pushed :debug in *features*, set (declaim (optimize (debug 3))), set *database* and *compiled-query-cache*.
NIL
PRCT> (mapc #L(handler-case (drop-table !1)
                (error (e) (declare (ignore e))))
            '(_c1 _c2 _c3 _c4))
(|_C1| |_C2| |_C3| |_C4|)
PRCT> (start-sql-recording)
; No value
PRCT> (defpclass c1 ()
        ((s1 :type string :initform "no" :initarg :s1 :accessor s1-of)))
#<PERSISTENT-CLASS C1>
PRCT> (with-transaction
        (make-instance 'c1 :s1 "hello"))
; BEGIN
; SELECT relname FROM pg_class WHERE relkind = 'r'
; CREATE TABLE _c1 (_id BIGINT NOT NULL PRIMARY KEY, _s1 TEXT)
; COMMIT
; BEGIN
; SELECT relname FROM pg_class WHERE relkind = 'S'
; SELECT NEXTVAL('_instance_id')
; $1 = 14279101191 as BIGINT, $2 = hello as TEXT
; INSERT INTO _c1 (_id, _s1) VALUES ($1::BIGINT, $2::TEXT)
; COMMIT
#<C1 :persistent #t 217881 {1008D782E1}>
PRCT> (defpclass c2 (c1)
        ((s2 :type (or null integer-16) :initarg :s2 :accessor s2-of)))
#<PERSISTENT-CLASS C2>
PRCT> (with-transaction
        (s1-of (make-instance 'c2 :s1 "hello" :s2 12)))
; BEGIN
; SELECT relname FROM pg_class WHERE relkind = 'r'
; CREATE TABLE _c2 (_id BIGINT NOT NULL PRIMARY KEY, _s2 SMALLINT)
; COMMIT
; BEGIN
; SELECT NEXTVAL('_instance_id')
; $1 = 14279177615 as BIGINT, $2 = hello as TEXT
; INSERT INTO _c1 (_id, _s1) VALUES ($1::BIGINT, $2::TEXT)
; $1 = 14279177615 as BIGINT, $2 = 12 as SMALLINT
; INSERT INTO _c2 (_id, _s2) VALUES ($1::BIGINT, $2::SMALLINT)
; COMMIT
"hello"
PRCT> (with-transaction
        (select (o)
          (from (o c1))))
; in: LAMBDA (#:G3698 #:G3699 #:G3700 #:G3701 #:G3705 #:G3706)
;     (EQL SB-PCL::.CASE-ARG. #:G3698)
; 
; note: unable to
;   optimize
; due to type uncertainty:
;   The first argument is a T, not a SINGLE-FLOAT.
;   The second argument is a T, not a SINGLE-FLOAT.
; 
; note: unable to
;   optimize
; due to type uncertainty:
;   The first argument is a T, not a DOUBLE-FLOAT.
;   The second argument is a T, not a DOUBLE-FLOAT.
; 
; note: forced to do GENERIC-EQL (cost 10)
;       unable to do inline fixnum comparison (cost 4) because:
;       The first argument is a T, not a FIXNUM.
;       The second argument is a T, not a FIXNUM.
; 
; compilation unit finished
;   printed 3 notes
; BEGIN
; SELECT _o._id, _o._s1 FROM _c1 _o
; COMMIT
(#<C1 :persistent #t 217881 {100AD18AE1}> #<C2 :persistent #t 217882 {100B002041}>)
PRCT> (defpclass c3 ()
        ((s3 :type c1 :initarg :s3 :accessor s3-of)))
#<PERSISTENT-CLASS C3>
PRCT> (let ((o
             (with-transaction
               (make-instance 'c3 :s3 (make-instance 'c2 :s2 nil)))))
        (with-transaction
          (revive-instance o)
          (s2-of (s3-of o))))
; BEGIN
; SELECT NEXTVAL('_instance_id')
; $1 = 14279243151 as BIGINT, $2 = no as TEXT
; INSERT INTO _c1 (_id, _s1) VALUES ($1::BIGINT, $2::TEXT)
; $1 = 14279243151 as BIGINT, $2 = NULL as SMALLINT
; INSERT INTO _c2 (_id, _s2) VALUES ($1::BIGINT, $2::SMALLINT)
; BEGIN
; SELECT relname FROM pg_class WHERE relkind = 'r'
; CREATE TABLE _c3 (_id BIGINT NOT NULL PRIMARY KEY, _s3_id BIGINT)
; select indexname from pg_indexes where tablename = '_c3'
; CREATE INDEX _s3_id_on_c3_idx ON _c3 (_s3_id)
; COMMIT
; SELECT NEXTVAL('_instance_id')
; $1 = 14279250170 as BIGINT, $2 = 14279243151 as BIGINT
; INSERT INTO _c3 (_id, _s3_id) VALUES ($1::BIGINT, $2::BIGINT)
; COMMIT
; BEGIN
; $1 = 14279250170 as BIGINT
; SELECT _c3._s3_id FROM _c3 _c3 WHERE ((_c3._id = $1::BIGINT))
; $1 = 14279243151 as BIGINT
; SELECT _c1._s1, _c2._s2 FROM _c1 _c1, _c2 _c2 WHERE ((_c1._id = $1::BIGINT) AND (_c1._id = _c2._id))
; COMMIT
NIL
PRCT> (defpclass c4 ()
        ())
#<PERSISTENT-CLASS C4>
PRCT> (defassociation
        ((:class c4 :slot c1s :type (set c1) :accessor c1s-of :initarg :c1s)
         (:class c1 :slot c4 :type c4 :accessor c4-of :initarg :c4)))
C4~C1S~C1~C4
PRCT> (with-transaction
        (make-instance 'c1 :c4 (make-instance 'c4)))
; BEGIN
; SELECT relname FROM pg_class WHERE relkind = 'r'
; CREATE TABLE _c4 (_id BIGINT NOT NULL PRIMARY KEY)
; SELECT relname FROM pg_class WHERE relkind = 'r'
; SELECT pg_attribute.attname, pg_type.typname, pg_attribute.attlen,
                                   pg_attribute.atttypmod, pg_attribute.attnotnull
                            FROM pg_type, pg_class, pg_attribute
                            WHERE pg_class.oid = pg_attribute.attrelid AND
                                  pg_class.relname = '_c1' AND
                                  pg_attribute.attname NOT IN ('cmin', 'cmax', 'xmax', 'xmin', 'oid', 'ctid', 'tableoid') AND
                                  pg_attribute.attisdropped = FALSE AND
                                  pg_attribute.atttypid = pg_type.oid
; ALTER TABLE _c1 ADD _c4_id BIGINT
; select indexname from pg_indexes where tablename = '_c1'
; CREATE INDEX _c4_id_on_c1_idx ON _c1 (_c4_id)
; COMMIT
; BEGIN
; SELECT NEXTVAL('_instance_id')
; $1 = 14279354071 as BIGINT
; INSERT INTO _c4 (_id) VALUES ($1::BIGINT)
; SELECT NEXTVAL('_instance_id')
; $1 = 14279428871 as BIGINT, $2 = no as TEXT, $3 = 14279354071 as BIGINT
; INSERT INTO _c1 (_id, _s1, _c4_id) VALUES ($1::BIGINT, $2::TEXT, $3::BIGINT)
; COMMIT
#<C1 :persistent #t 217886 {100A1664D1}>
PRCT> (with-transaction
        (let ((c4 (select-first-matching-instance c4)))
          (select ((c4-of c1) (s1-of c1))
            (from (c1 c1))
            (where (eq c4 (c4-of c1))))))
; BEGIN
; SELECT COUNT(*) FROM (SELECT __instance_._id FROM _c4 __instance_) records
; SELECT __instance_._id FROM _c4 __instance_ LIMIT 1 OFFSET 0
; BEGIN
; SELECT relname FROM pg_class WHERE relkind = 'r'
; SELECT pg_attribute.attname, pg_type.typname, pg_attribute.attlen,
                                   pg_attribute.atttypmod, pg_attribute.attnotnull
                            FROM pg_type, pg_class, pg_attribute
                            WHERE pg_class.oid = pg_attribute.attrelid AND
                                  pg_class.relname = '_c2' AND
                                  pg_attribute.attname NOT IN ('cmin', 'cmax', 'xmax', 'xmin', 'oid', 'ctid', 'tableoid') AND
                                  pg_attribute.attisdropped = FALSE AND
                                  pg_attribute.atttypid = pg_type.oid
; COMMIT
; SELECT _c1._c4_id, _c1._s1 FROM _c1 _c1 WHERE (((NOT (14279354071 IS NULL)) AND (14279354071 = _c1._c4_id)))
; COMMIT
((#<C4 :persistent #t 217885 {100ADDBEA1}> "no"))
PRCT> (with-transaction
        (let ((c4 (caar *)))
          (select ((c4-of c1) (s1-of c1))
            (from (c1 c1))
            (where (eq c4 (c4-of c1))))))
; BEGIN
; SELECT _c1._c4_id, _c1._s1 FROM _c1 _c1 WHERE (((NOT (14279354071 IS NULL)) AND (14279354071 = _c1._c4_id)))
; COMMIT
((#<C4 :persistent #? 217885 {10099F7591}> "no"))
PRCT>