Re: CLSQL - feature request?

From: Dmitri Ivanov (divanov_NOSP_at_M_.aha.ru)
Date: 05/19/04


Date: Wed, 19 May 2004 10:20:58 +0400

Hello Will,
"Will Hartung" <willh@msoft.com> wrote:

WH> | ...snip...|
WH> For ODBC, it's not really important as the actual back end ODBC
WH> driver does all of the work for the DB anyway, so who know what
WH> it's actually doing.
WH>
WH> Also, most of the Lisp SQL interfaces do the same thing,
WH> essentially recreating the complete SQL ASCII statement for each
WH> request.

Recreating an SQL statement is not always possible due to the maximum length
limitation imposed by the DBMS or driver. The pathological case is when the
SQL statement for passing binary data cannot be constructed at all due to
the lack of the corresponding data type text representation.

WH> On the other hand, for an actual binary SQL protocol (ala Oracle
WH> OCI), then you need to marshall the binary data into and out of the
WH> Lisp process anyway, so I dunno if even then we'd get much of a
WH> performance benefit.
WH>
WH> Not to say that there isn't a semantic benefit to being able to
WH> simply build a SQL statement and set parameters over and over,
WH> making it easier on the developer. But one of the primary
WH> motivations behing prepared statements was simply performance, not
WH> necessarily semanatics, so I'm curious if a CL based SQL layer will
WH> actually be able to benefit from prepared statements at the
WH> performance level.

The answer is 'Yes'. The following rude benchmarks come from testing YSQL on
LW over the Access ODBC driver:

;; Without preparing
(time
(dotimes (i 1000)
   (sql:with-transaction ()
     (sql:insert-records :into [tab2]
                     :attributes '([id] [text2_])
                     :values (list i (format nil "~A" (random 1000)))))))
; user time = 5.015
; system time = 0.703
; Elapsed time = 0:00:06
; Allocation = 3887584 bytes standard / 5264677 bytes fixlen
; 0 Page faults

;; With preparing
(time
  (sql:with-prepared-statement (stmt [insert :into [tab2]
     :attributes '([id] [text2_])
      :values '([? :type integer] [? :type string])])
    (sql:with-transaction ()
      (dotimes (i 1000)
        (sql:execute-command stmt
          :values (list i (format nil "~A" (random 1000))))))))
; user time = 0.890
; system time = 0.093
; Elapsed time = 0:00:01
; Allocation = 647984 bytes standard / 1573990 bytes fixlen
; 0 Page faults

FWIW, the example below demonstrates the syntactical sugar for dealing with
parameters in YSQL.

(setq pa (sql:prepare-statement
    [insert :into [tab]
        :attributes '([Text_] [Boolean_] [Currency_] [DateTime_]
                           [Byte_] [Short_] [Long_] [Single_] [Double_])
            :values '([? :name text_ :type string]
                      [? :name boolean_ :type :boolean]
                      [? :name Currency_ :type :numeric]
                      [? :name DateTime_ :type :timestamp]
                      [? :name Byte_ :type unsigned-byte]
                      [? :name Short_ :type (integer -32767 32767)]
                      [? :name Long_ :type integer]
                      [? :name Single_ :type single-float]
                      [? :name Double_ :type double-float]) ]
    :database a))
(sql:execute-command pa
    :values `("From prepared" 0 111.11 ,(get-universal-time)
         255 222 3333 4.44 55.5555))

--
Sincerely,
Dmitri Ivanov
lisp.ystok.ru


Relevant Pages

  • Re: GetColAtrribute() with SQL_DESC_OCTET_LENGTH parameter
    ... I am connecting to various RBDMS but primarily SQL ... > Server and MySQL using ODBC 3.0 driver. ...
    (microsoft.public.data.odbc)
  • Re: database questions ala newbie pythonist
    ... > whatever else is necessary to build a valid SQL statement. ... is less than satisfactory in certain respects, and the odbc module ... I'm not quite sure why string substitution was used for the ProductID ... This does indeed generate a well-formed SQL statement, ...
    (comp.lang.python)
  • Re: Copying Data from Access to SQL Server
    ... ODBC often sends one row at a time: ... know ODBC sends a different SQL statement for each row in an INSERT ... UPDATE, INSERT, and DELETE queries operating on SQL Server tables -- is ... The query processor then ...
    (comp.databases.ms-access)
  • Re: return yesterdays date?
    ... in SQL Server you might be able to do the following: ... but the DATEADDfunction is part of T-SQL and is passed through the ODBC ... It is not processed in the driver. ... I'm using an odbc driver provided by the database vendor I'm ...
    (microsoft.public.data.odbc)
  • Re: Delete a line in a text file
    ... you can use the ODBC text driver & ADO to select ... using SQL, either using the ODBC text driver or the OLE DB ...
    (microsoft.public.excel.programming)