[Cl-perec-devel] Optimization question

Mihai Bazon mihai at bazon.net
Fri Oct 9 13:00:35 UTC 2009


Hi folks,

Here are two variants, I'd say equivalent, to select some objects:

   (select-instances (o) (where (typep o 'db-group)))

   (defvar tmp 'db-user)
   (select-instances (o) (where (typep o tmp)))

Both work the same, but the first one is better because it results in a
single select that fetches the data as well.  Here's what I see using
start-sql-recording:

1st version:

; SELECT _o._oid, _o._edition, _o._name, _o._description FROM _db_group_ap _o

2nd version:

; SELECT _o._oid FROM _db_group_ai _o
; $1 = 69012 as BIGINT
; SELECT _edition, _name, _description FROM _db_group_dd WHERE (_oid = $1::BIGINT)
; $1 = 134548 as BIGINT
; SELECT _edition, _name, _description FROM _db_group_dd WHERE (_oid = $1::BIGINT)
; $1 = 200084 as BIGINT
; SELECT _edition, _name, _description FROM _db_group_dd WHERE (_oid = $1::BIGINT)

I presume there's some compile-time magic that happens in case 1 and not
in case 2.  I can't hard-code the type so I'd like to use the second
variant, but is it possible to optimize it so that it results in a
single select like the first one?

Thanks for any hints!
-Mihai



More information about the cl-perec-devel mailing list