korma/Korma — pull request #189 by jryancarr (2013-11-22 19:05:27+00:00)
Title: Passing through JDBC options.

Added functionality to set and pass through two JDBC options (:fetch-size and :max-rows) to clojure.java.jdbc's prepare-statement.

Fetch size is important because large queries to a remote server are intolerably slow with the default fetch size of 10.

Max rows is important because the only simple way Korma currently provides to limit the number of rows returned is the (limit) function, which relies on SQL LIMIT, which is not supported by Oracle. The only workaround my group was able to find was to run our original query as a subselect, then call (where (raw (str "rownum <= " X))), but this has the problem of not automatically calling any transforms defined for entities in the subselect. Being able to call (select users (max-rows X)) solves this.

Some usage examples, with performance for one of the large tables my group uses:

user=> (defdb b (korma.db/oracle {...}}))
{:pool …}
user=> (defentity ent (table ...))
#'user/ent
user=> (count (time (select ent (fields :name))))
"Elapsed time: 14443.238 msecs"
17178
user=> (count (time (select ent (fields :name))))
"Elapsed time: 14247.032 msecs"
17178
user=> (count (time (select ent (fields :name))))
"Elapsed time: 14024.118 msecs"
17178
user=> (count (time (select ent (fields :name) (fetch-size 100))))
"Elapsed time: 1812.418 msecs"
17178
user=> (count (time (select ent (fields :name) (fetch-size 1000))))
"Elapsed time: 353.63 msecs"
17178

user=> (count (time (select ent (fields :name) (max-rows 100))))
"Elapsed time: 160.334 msecs"
100
user=> (count (time (select ent (fields :name) (limit 100)))) ;;Oracle doesn't support LIMIT.
Failure to execute query with SQL:
SELECT “TABLE_NAME.”NAME" FROM “TABLE_NAME” LIMIT 100 :: []
SQLSyntaxErrorException:
Message: ORA-00933: SQL command not properly ended

SQLState: 42000
Error Code: 933

SQLSyntaxErrorException ORA-00933: SQL command not properly ended
oracle.jdbc.driver.T4CTTIoer.processError (T4CTTIoer.java:445)