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

Create views for often - used expressions #106

Open
bendlas opened this issue Aug 26, 2011 · 1 comment
Open

Create views for often - used expressions #106

bendlas opened this issue Aug 26, 2011 · 1 comment

Comments

@bendlas
Copy link
Collaborator

bendlas commented Aug 26, 2011

I'm thinking of a defview form, that gets a cql table, like

(defview customer-sales
  (-> (table :customer)
      (join (table :sales) (where (= :sales.customer :customer.id)))))

It creates a view customer_sales_view in the DB with the compiled sql and sets a :view "customer_sales_view" key on the cql table. If the view already exists, it checks whether the definition of the view equals the compiled sql.

When you use a table with a :view key in an expression, or deref directly, the compiler uses the precreated database view in the generated sql.

Pros

  • efficient: CQL only needs to compile once, DB Server only needs to parse and compile once, DB Server can pre-optimize
  • explicit: It gives visibility to the main building blocks in a given piece of data layer code
  • familiar: It supports the workflow, DB programmers are used to. Using views for reused subexpressions is regarded a sign of good database engineering.
  • reduces need for automatic memoizing of compiled expressions

Cons

  • first DDL statement in ClojureQL
  • preexisting views might get overwritten, maybe add a special token to generated view names
  • not all db implementations might handle views equally efficient

The first one is the biggie. I think it's best to punt the horrid issues of automatic schema upgrade, by refusing to automatically replace a view, if it's different to the one we want to intern. Yes, this means we need to compare two token streams in defview.


What do you think of it?

@ghost
Copy link

ghost commented Feb 21, 2012

+1, it's a worthwhile idea

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

No branches or pull requests

1 participant