{"action":"created","issue":{"url":"https://api.github.com/repos/cpv-project/cpv-cql-driver/issues/13","repository_url":"https://api.github.com/repos/cpv-project/cpv-cql-driver","labels_url":"https://api.github.com/repos/cpv-project/cpv-cql-driver/issues/13/labels{/name}","comments_url":"https://api.github.com/repos/cpv-project/cpv-cql-driver/issues/13/comments","events_url":"https://api.github.com/repos/cpv-project/cpv-cql-driver/issues/13/events","html_url":"https://github.com/cpv-project/cpv-cql-driver/issues/13","id":307476273,"number":13,"title":"Better support for prepared statement","user":{"login":"303248153","id":16222094,"avatar_url":"https://avatars2.githubusercontent.com/u/16222094?v=4","gravatar_id":"","url":"https://api.github.com/users/303248153","html_url":"https://github.com/303248153","followers_url":"https://api.github.com/users/303248153/followers","following_url":"https://api.github.com/users/303248153/following{/other_user}","gists_url":"https://api.github.com/users/303248153/gists{/gist_id}","starred_url":"https://api.github.com/users/303248153/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/303248153/subscriptions","organizations_url":"https://api.github.com/users/303248153/orgs","repos_url":"https://api.github.com/users/303248153/repos","events_url":"https://api.github.com/users/303248153/events{/privacy}","received_events_url":"https://api.github.com/users/303248153/received_events","type":"User","site_admin":false},"labels":[{"id":781425805,"url":"https://api.github.com/repos/cpv-project/cpv-cql-driver/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"closed","locked":false,"assignee":{"login":"303248153","id":16222094,"avatar_url":"https://avatars2.githubusercontent.com/u/16222094?v=4","gravatar_id":"","url":"https://api.github.com/users/303248153","html_url":"https://github.com/303248153","followers_url":"https://api.github.com/users/303248153/followers","following_url":"https://api.github.com/users/303248153/following{/other_user}","gists_url":"https://api.github.com/users/303248153/gists{/gist_id}","starred_url":"https://api.github.com/users/303248153/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/303248153/subscriptions","organizations_url":"https://api.github.com/users/303248153/orgs","repos_url":"https://api.github.com/users/303248153/repos","events_url":"https://api.github.com/users/303248153/events{/privacy}","received_events_url":"https://api.github.com/users/303248153/received_events","type":"User","site_admin":false},"assignees":[{"login":"303248153","id":16222094,"avatar_url":"https://avatars2.githubusercontent.com/u/16222094?v=4","gravatar_id":"","url":"https://api.github.com/users/303248153","html_url":"https://github.com/303248153","followers_url":"https://api.github.com/users/303248153/followers","following_url":"https://api.github.com/users/303248153/following{/other_user}","gists_url":"https://api.github.com/users/303248153/gists{/gist_id}","starred_url":"https://api.github.com/users/303248153/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/303248153/subscriptions","organizations_url":"https://api.github.com/users/303248153/orgs","repos_url":"https://api.github.com/users/303248153/repos","events_url":"https://api.github.com/users/303248153/events{/privacy}","received_events_url":"https://api.github.com/users/303248153/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/cpv-project/cpv-cql-driver/milestones/2","html_url":"https://github.com/cpv-project/cpv-cql-driver/milestone/2","labels_url":"https://api.github.com/repos/cpv-project/cpv-cql-driver/milestones/2/labels","id":3189487,"number":2,"title":"0.2","description":"","creator":{"login":"303248153","id":16222094,"avatar_url":"https://avatars2.githubusercontent.com/u/16222094?v=4","gravatar_id":"","url":"https://api.github.com/users/303248153","html_url":"https://github.com/303248153","followers_url":"https://api.github.com/users/303248153/followers","following_url":"https://api.github.com/users/303248153/following{/other_user}","gists_url":"https://api.github.com/users/303248153/gists{/gist_id}","starred_url":"https://api.github.com/users/303248153/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/303248153/subscriptions","organizations_url":"https://api.github.com/users/303248153/orgs","repos_url":"https://api.github.com/users/303248153/repos","events_url":"https://api.github.com/users/303248153/events{/privacy}","received_events_url":"https://api.github.com/users/303248153/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":2,"state":"open","created_at":"2018-03-15T06:43:19Z","updated_at":"2018-03-28T07:46:21Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2018-03-22T01:42:47Z","updated_at":"2018-03-28T07:59:00Z","closed_at":"2018-03-28T07:46:20Z","author_association":"CONTRIBUTOR","body":"For better performance, I should rethink the design about prepared statement.\r\nFor high level, there two design:\r\n\r\nPrepare the statement explicitly:\r\n\r\n``` c++\r\nsession.prepare(\"select name from abc where id = ?\").then([] (cql::PreparedQuery query) {\r\n    auto command = cql::Command(query)\r\n        .addParameters(cql::Int(123));\r\n    return session.query(std::move(command));\r\n}).then([] (cql::ResultSet result) {\r\n    // ...\r\n});\r\n```\r\n\r\nPrepare the statement implicitly (like the batch command):\r\n\r\n``` c++\r\nauto command = cql::Command(\"select name from abc where id = ?\")\r\n    .prepareQuery()\r\n    .addParameters(cql::Int(123));\r\nsession.query(std::move(command)).then([] (cql::ResultSet result) {\r\n    // ...\r\n});\r\n```\r\n\r\nI personally prefer the implicitly solution, it's easier to manage and reduce user work, but it needs a hash map to associate query string and prepared query id.\r\n\r\n--------------------------------------------------------\r\n\r\nFor low level, things are complicated.\r\nFor `Session::query` and `Session::execute` I can do this:\r\n\r\n``` text\r\nconnection = pool.getConnection()\r\nnode = connection.node\r\nid = preparedQuery[node]\r\nif  (id == nullptr) {\r\n    id = connection.send(prepareMessage)\r\n    preparedQuery[node] = id\r\n}\r\nresult = connection.send(executeMessage)\r\nif (result.error && result.errorCode == 0x2500) {\r\n    id = connection.send(prepareMessage)\r\n    preparedQuery[node] = id\r\n    result = connection.send(executeMessage)\r\n}\r\nreturn result\r\n```\r\n\r\nBut for `Session::batchExecute`, I don't know what's the best solution.\r\n\r\nFor example I send a batch with prepared statement A, B, C,\r\nA is prepared on the node but B and C does not,\r\nwill the server execute statement A, made the side effect, then return an unprepared error?\r\n\r\nAnd since 0x2500 only return a single id in [short bytes], I need to retry many times like:\r\n\r\n- send a batch with prepared statement A, B, C\r\n- server return an error indicates B has not prepared\r\n- prepare B\r\n- send a batch with prepared statement A, B, C\r\n- server return an error indicates C has not prepared\r\n- prepare C\r\n- send a batch with prepared statement A, B, C\r\n- success\r\n\r\nCompare to the solution I'm using for now (version 0.1):\r\n\r\n- prepare A anyway\r\n- prepare B anyway\r\n- prepare C anyway\r\n- send a batch with prepared statement A, B, C\r\n\r\n--------------------------------------------------------\r\n\r\nImprove the prepare process:\r\n\r\nFor now prepare multiple statements I will wait for each response before next request:\r\n\r\n- send PREPARE\r\n- wait RESULT or ERROR\r\n- send PREPARE\r\n- wait RESULT or ERROR\r\n- send PREPARE\r\n- wait RESULT or ERROR\r\n\r\nI can change it to (pipeline):\r\n\r\n- send PREPARE\r\n- send PREPARE\r\n- send PREPARE\r\n- wait RESULT or ERROR\r\n- wait RESULT or ERROR\r\n- wait RESULT or ERROR\r\n"},"comment":{"url":"https://api.github.com/repos/cpv-project/cpv-cql-driver/issues/comments/376796614","html_url":"https://github.com/cpv-project/cpv-cql-driver/issues/13#issuecomment-376796614","issue_url":"https://api.github.com/repos/cpv-project/cpv-cql-driver/issues/13","id":376796614,"user":{"login":"303248153","id":16222094,"avatar_url":"https://avatars2.githubusercontent.com/u/16222094?v=4","gravatar_id":"","url":"https://api.github.com/users/303248153","html_url":"https://github.com/303248153","followers_url":"https://api.github.com/users/303248153/followers","following_url":"https://api.github.com/users/303248153/following{/other_user}","gists_url":"https://api.github.com/users/303248153/gists{/gist_id}","starred_url":"https://api.github.com/users/303248153/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/303248153/subscriptions","organizations_url":"https://api.github.com/users/303248153/orgs","repos_url":"https://api.github.com/users/303248153/repos","events_url":"https://api.github.com/users/303248153/events{/privacy}","received_events_url":"https://api.github.com/users/303248153/received_events","type":"User","site_admin":false},"created_at":"2018-03-28T07:59:00Z","updated_at":"2018-03-28T07:59:00Z","author_association":"CONTRIBUTOR","body":"I will update the [Benchmark](https://github.com/cpv-project/cpv-cql-driver/blob/master/docs/Benchmark.md) before release 0.2.\r\nHopefully in this week."}}
{"actor":{"display_login":"303248153"}}