cluster is becoming unresponsive when Querying with unindexed column with small load
We have 10 node cluster, each node is running on 8 core CPU and 32GB RAM, with two datacenter (central and east) , 5 nodes in central and 5 nodes in east and have replication factor=6 and 3 per DC is the constraint specified.
Below is the table
CREATE TABLE orders (
id UUID NOT NULL,
order_json STRING NOT NULL,
order_number STRING NOT NULL,
guest_id STRING NOT NULL,
failed_publish BOOL NULL,
failed_publish_avro BOOL NULL,
CONSTRAINT orders_pkey PRIMARY KEY (id ASC),
UNIQUE INDEX orders_id_key (id ASC),
INDEX orders_order_number_index (order_number ASC),
FAMILY "primary" (id, order_json, order_number, guest_id, failed_publish, failed_publish_avro)
)
Query used: SELECT order_json FROM orders WHERE guest_id = $1
guest_id is non indexed column
when a load of 50 users is applied, it had upto 12/s queries CPU had gone beyond 95% for 3 of the nodes and started seeing nodes going down and they all got restarted. UI stopped loading, and then this continued to happen until load was on. When the load was stopped cluster came back to Normal
Is this behavior expected? Querying with unindexed column can have a bad performance but this is actually making cluster go unresponsive. would like to know why is it happening or is there a way we can avoid this situation (if we do not want to index)?
Is it because of type UUID ?
Hey @kswathihs,
The issue is most likely the fact that you are querying on a non indexed column, if that table is of any appreciable size then you'll run into issues like these. When querying on the non indexed column, you are spanning the entire table each time you execute the query.
Here is an explain both with and without an index on guest_id:
WITHOUT INDEX
oot@:26257/defaultdb> EXPLAIN (verbose) SELECT order_json FROM orders WHERE guest_id = 'djf8fjf'; tree | field | description | columns | ordering
+-----------+----------+----------------------+------------------------+----------+
render | | | (order_json) |
│ | render 0 | order_json | |
└── scan | | | (order_json, guest_id) |
| table | orders@orders_pkey | |
| spans | ALL | |
| filter | guest_id = 'djf8fjf' | |
WITH INDEX
root@:26257/defaultdb> EXPLAIN (verbose) SELECT order_json FROM orders WHERE guest_id = 'djf8fjf';
tree | field | description | columns | ordering
+-----------------+----------+---------------------------------+------------------------+----------+
render | | | (order_json) |
│ | render 0 | order_json | |
└── index-join | | | (order_json, guest_id) |
│ | table | orders@orders_pkey | |
└── scan | | | (id, guest_id) |
| table | orders@orders_guest_id_idx | |
| spans | /"djf8fjf"-/"djf8fjf"/PrefixEnd | |
I would suggest creating an index, and then trying this again, if there is no change in performance, then please send us your schema and query plan.
Thanks!
Thanks @roncrdb. I agree to the perf improvement fact with indexing but the behavior of cockroach here is that it is making the cluster unresponsive with high CPU on nodes and nodes getting restarted. so not just those queries but the entire DB and other clients who has connected are impacted as well. This mandates to have index for all the frequently used queries right? not just for perf improvement but to avoid DB going unresponsive.
Hello @kswathihs
I hope all is well. If you are still having the issue, how are the Cockroach nodes provisioned (CPU, mem, etc), and is the query being run through a load balancer, or directly on one of the nodes?
Cheers, Ricardo
Closing due to inactivity. If you are still having the issue, please feel free to respond to this thread. We want to help!