cassandra-data-apis icon indicating copy to clipboard operation
cassandra-data-apis copied to clipboard

Excessive query preparations for a single query

Open jorgebay opened this issue 5 years ago • 1 comments

As in golang map keys order is not guaranteed, multiple CQL queries are prepared given a single graphql query, when executing multiple times.

Consider the following query:

mutation {
  insertTagsByLetter(value: {firstLetter: "b", tag: "bote"}){
    applied
    value { tag }
  }
}

When executing multiple times, we generate 2 different prepared queries:

INSERT INTO "killrvideo"."tags_by_letter" ("tag", "first_letter") VALUES (?, ?)
INSERT INTO "killrvideo"."tags_by_letter" ("first_letter", "tag") VALUES (?, ?)

On larger queries, this posses a real issue as prepared statement cache might fill up and queries get evicted server side.

jorgebay avatar Apr 28 '20 09:04 jorgebay

The fix is to sort the keys and use those for iteration.

jorgebay avatar Apr 28 '20 09:04 jorgebay