Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data PrepQuery k a b
- prepared :: QueryString k a b -> PrepQuery k a b
- queryString :: PrepQuery k a b -> QueryString k a b
- data PreparedQueries
- new :: IO PreparedQueries
- lookupQueryId :: PrepQuery k a b -> PreparedQueries -> STM (Maybe (QueryId k a b))
- lookupQueryString :: QueryId k a b -> PreparedQueries -> STM (Maybe (QueryString k a b))
- insert :: PrepQuery k a b -> QueryId k a b -> PreparedQueries -> STM ()
- delete :: PrepQuery k a b -> PreparedQueries -> STM ()
- queryStrings :: PreparedQueries -> STM [Text]
Documentation
Representation of a prepared QueryString
. A prepared query is
executed in two stages:
- The query string is sent to a server without parameters for
preparation. The server responds with a
QueryId
. - The prepared query is executed by sending the
QueryId
and parameters to the server.
Thereby step 1 is only performed when the query has not yet been prepared with the host (coordinator) used for query execution. Thus, prepared queries enhance performance by avoiding the repeated sending and parsing of query strings.
Query preparation is handled transparently by the client.
See setPrepareStrategy
.
Note
Prepared statements are fully supported but rely on some assumptions beyond the scope of the CQL binary protocol specification (spec):
- The spec scopes the
QueryId
to the node the query has been prepared with. The spec does not state anything about the format of theQueryId
. However the official Java driver assumes that any givenQueryString
yields the sameQueryId
on every node. This client make the same assumption. - In case a node does not know a given
QueryId
anUnprepared
error is returned. We assume that it is always safe to transparently re-prepare the correspondingQueryString
and to re-execute the original request against the same node.
Besides these assumptions there is also a potential tradeoff in
regards to eager vs. lazy query preparation.
We understand eager to mean preparation against all current nodes of
a cluster and lazy to mean preparation against a single node on demand,
i.e. upon receiving an Unprepared
error response. Which strategy to
choose depends on the scope of query reuse and the size of the cluster.
The global default can be changed through the Settings
module as well
as locally using withPrepareStrategy
.
Instances
IsString (PrepQuery k a b) Source # | |
Defined in Database.CQL.IO.PrepQuery fromString :: String -> PrepQuery k a b # |
prepared :: QueryString k a b -> PrepQuery k a b Source #
queryString :: PrepQuery k a b -> QueryString k a b Source #
data PreparedQueries Source #
new :: IO PreparedQueries Source #
lookupQueryId :: PrepQuery k a b -> PreparedQueries -> STM (Maybe (QueryId k a b)) Source #
lookupQueryString :: QueryId k a b -> PreparedQueries -> STM (Maybe (QueryString k a b)) Source #
queryStrings :: PreparedQueries -> STM [Text] Source #