본문 바로가기
개발

[cassandra] datastax bind vs prepared statement

by eun2ce 2022. 8. 9.

datastax statement를 이용하는 데 있어서 bind와 prepared 두 가지 쿼리 방식이 존재합니다.

작업에 어떤 것이 더 적합한지 무엇이 다른지에 대해 확인하는 내용에 대해 작성 한 글입니다.

bind statement vs prepared statement

https://docs.datastax.com/en/developer/java-driver/3.0/manual/statements/prepared/

 

DataStax Java Driver - Prepared statements

finally, if the driver tries to execute a statement and finds out that the coordinator doesn’t know about it, it will re-prepare the statement on the fly (this is transparent for the client, but will cost two extra roundtrips):

docs.datastax.com

 

prepared statement는 미리 만들어두고 execute 할 때 prepared statement로부터 bind statement를 생성하여 처리합니다,

  • prepared statement는 매 번 만들어내지 않습니다.

execute async 할 때는 execution 하나 당 하나의 bind statement를 생성하여 처리합니다.

 

idempotent 한 쿼리 빌드

함수 refer

/**
 * Whether this statement is idempotent, i.e. whether it can be applied multiple times without
 * changing the result beyond the initial application.
 *
 * <p>If a statement is <em>not idempotent</em>, the driver will ensure that it never gets
 * executed more than once, which means:
 *
 * <ul>
 *   <li>avoiding {@link RetryPolicy retries} on write timeouts or request errors;
 *   <li>never scheduling {@link com.datastax.driver.core.policies.SpeculativeExecutionPolicy
 *       speculative executions}.
 * </ul>
 *
 * (this behavior is implemented in the driver internals, the corresponding policies will not even
 * be invoked).
 *
 * <p>Note that this method can return {@code null}, in which case the driver will default to
 * {@link QueryOptions#getDefaultIdempotence()}.
 *
 * <p>By default, this method returns {@code null} for all statements, except for
 *
 * <ul>
 *   <li>{@link BuiltStatement} - value will be inferred from the query: if it updates counters,
 *       prepends/appends to a list, or uses a function call or {@link
 *       com.datastax.driver.core.querybuilder.QueryBuilder#raw(String)} anywhere in an inserted
 *       value, the result will be {@code false}; otherwise it will be {@code true}.
 *   <li>{@link com.datastax.driver.core.querybuilder.Batch} and {@link BatchStatement}:
 *       <ol>
 *         <li>If any statement in batch has isIdempotent() false - return false
 *         <li>If no statements with isIdempotent() false, but some have isIdempotent() null -
 *             return null
 *         <li>Otherwise - return true
 *       </ol>
 * </ul>
 *
 * In all cases, calling {@link #setIdempotent(boolean)} forces a value that overrides calculated
 * value.
 *
 * <p>Note that when a statement is prepared ({@link Session#prepare(String)}), its idempotence
 * flag will be propagated to all {@link PreparedStatement}s created from it.
 *
 * @return whether this statement is idempotent, or {@code null} to use {@link
 *     QueryOptions#getDefaultIdempotence()}.
 */
public Boolean isIdempotent() {
  return idempotent;
}

https://docs.datastax.com/en/developer/java-driver/4.2/manual/query_builder/idempotence/

Future인데 초기에 구동시키는 object 일 경우, 굳이 async 일 필요 없습니다.

'개발' 카테고리의 다른 글

[elasticsearch] maximum normal shards open 에러  (0) 2022.09.07
tar gz 압축 및 해제  (0) 2022.09.07
[cassandra] Detected a synchronous call on an I/O thread  (0) 2022.08.09
port kill  (0) 2022.08.06
mac Microk8s 설치  (0) 2022.08.06