SELECT count(*) as ccc FROM
xxxWHERE _type='au' AND src = 'blog' AND create_time >= 1 AND create_time <= 20000000000 AND id IS NOT MISSING LIMIT 101 OFFSET 0
This query return:
[ { "ccc": 2784031 } ]
Then it’s just 2.7m records.
When query like this:
SELECT id, src, src_id, author, status, title, SUBSTR(body, 0, 500) as body, create_time, up_time, memo, history, result FROM
xxxWHERE _type='au' AND src = 'blog' AND create_time >= 1 AND create_time <= 20000000000 AND id IS NOT MISSING ORDER BY id DESC LIMIT 101 OFFSET 0
It result timeout…
The query explain like this:
{ "plan": { "#operator": "Sequence", "~children": [ { "#operator": "Sequence", "~children": [ { "#operator": "IndexScan3", "index": "idx_au_blog_createtime_id", "index_id": "af8bb3de1d546698", "index_projection": { "primary_key": true }, "keyspace": "xxx", "namespace": "default", "spans": [ { "exact": true, "range": [ { "high": "20000000000", "inclusion": 3, "low": "1" }, { "inclusion": 1, "low": "null" } ] } ], "using": "gsi" }, { "#operator": "Fetch", "keyspace": "xxx", "namespace": "default" }, { "#operator": "Parallel", "~child": { "#operator": "Sequence", "~children": [ { "#operator": "Filter", "condition": "((((((`xxx`.`_type`) = \"au\") and ((`xxx`.`src`) = \"blog\")) and (1 <= (`xxx`.`create_time`))) and ((`xxx`.`create_time`) <= 20000000000)) and ((`xxx`.`id`) is not missing))" }, { "#operator": "InitialProject", "result_terms": [ { "expr": "(`xxx`.`id`)" }, { "expr": "(`xxx`.`src`)" }, { "expr": "(`xxx`.`src_id`)" }, { "expr": "(`xxx`.`author`)" }, { "expr": "(`xxx`.`status`)" }, { "expr": "(`xxx`.`title`)" }, { "as": "body", "expr": "substr0((`xxx`.`body`), 0, 500)" }, { "expr": "(`xxx`.`create_time`)" }, { "expr": "(`xxx`.`up_time`)" }, { "expr": "(`xxx`.`memo`)" }, { "expr": "(`xxx`.`history`)" }, { "expr": "(`xxx`.`result`)" } ] } ] } } ] }, { "#operator": "Order", "limit": "101", "sort_terms": [ { "desc": true, "expr": "(`xxx`.`id`)" } ] }, { "#operator": "Limit", "expr": "101" }, { "#operator": "FinalProject" } ] }, "text": "SELECT id, src, src_id, author, status, title, SUBSTR(body, 0, 500) as body, create_time, up_time, memo, history, result FROM `xxx` WHERE _type='au' AND src = 'blog' AND create_time >= 1 AND create_time <= 20000000000 AND id IS NOT MISSING ORDER BY id DESC LIMIT 101 OFFSET 0" }
The idx_au_blog_createtime_id is:
CREATE INDEX `idx_au_blog_createtime_id` ON `xxx`(`create_time`,`id` DESC) WHERE ((`_type` = "au") and (`src` = "blog"))
Can someone check why the query is so slow or timeout and how to fix this?
Thanks a lot for any help.