Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing through JDBC options. #189

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

jryancarr
Copy link

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)

@e0d
Copy link

e0d commented Dec 27, 2014

This seems like a useful feature would be nice to see it merged or comments as to what's wrong with the current PR.

@immoh
Copy link
Member

immoh commented Jan 4, 2015

Instead of adding new function to the dsl for each configuration option, I would like to see a solution that allows passing arbitrary options to clojure.java.jdbc.

@e0d
Copy link

e0d commented Jan 5, 2015

Thoughts on what this would look like? Maybe a function with-options that takes a map as an argument?

@immoh
Copy link
Member

immoh commented Jan 5, 2015

Yeah, I was also thinking of something like this:

(with-options {:fetch-size 100 :max-rows 1000}
  (select users))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants