question

MarcoAugustoMARIANI-2275 avatar image
0 Votes"
MarcoAugustoMARIANI-2275 asked AnuragSharma-MSFT commented

CosmosDB - Cassandra API - Similar queries with different Request Charges

I need your help to better understand how the RU/s calculation works on Cosmos DB, with Cassandra API.

I created a table with the following details:

CREATE KEYSPACE IF NOT EXISTS mykeyspace WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'datacenter1' : 1 };

CREATE TABLE mykeyspace.data (
tenant_id text,
project_id text,
timestamp bigint,
metric_id text,
value double,
PRIMARY KEY ((tenant_id, project_id, metric_id), timestamp)
) WITH CLUSTERING ORDER BY (timestamp DESC);

I executed two different queries using the code suggested in https://docs.microsoft.com/it-it/azure/cosmos-db/find-request-unit-charge-cassandra to get "Request Charge" and obtained that:

1) "SELECT FROM mykeyspace.data WHERE metric_id='R15L2_lx_Msr_36_Id_1_15' AND project_id = '05dc67e7-4671-4d76-98d8-38354f1ec630' AND tenant_id = '5ee115749582159cdb' AND timestamp =1586960400000 LIMIT 1"
Request Charge=1.0*

2) "SELECT value FROM mykeyspace.data WHERE metric_id='R15L2_lx_Msr_36_Id_1_15' AND project_id = '05dc67e7-4671-4d76-98d8-38354f1ec630' AND tenant_id = '5ee115749582159cdb' AND timestamp =1586960400000 LIMIT 1"
Request Charge=4.1

Could you explain me why the second one had a higher charge?




azure-cosmos-db
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AnuragSharma-MSFT avatar image
0 Votes"
AnuragSharma-MSFT answered AnuragSharma-MSFT commented

Hi @MarcoAugustoMARIANI-2275 , welcome to Microsoft Q&A forum.

The reason 2nd query is taking higher charge is because we are trying to retrieve a column that is not indexed. In first query as we are returning every columns, the indexes don't matter.

I tried running same query after adding index on 'value' column and now the RUs are equals for both the queries. Below is the index you can create and try once:

 CREATE INDEX ON mykeyspace.data (value)

Please let me know if this helps or else we can discuss further on the same.


If answer helps, please mark it 'Accept Answer'



· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you @AnuragSharma-MSFT.
Are you sure? 'value' is used in selection part of query not as "where" condition. I don't understand because I have to create a index in this case (I remember you that we are using the Cassandra API). What is the reason? Moreover, can you help me to understand how CosmosDB obtain RequestCharge=4.1?

0 Votes 0 ·
AnuragSharma-MSFT avatar image AnuragSharma-MSFT MarcoAugustoMARIANI-2275 ·

Hi @MarcoAugustoMARIANI-2275, thanks for replying back.

You are right in mentioning that the value is not used in where condition so creating index on it should not matter, but after creating the index on it we see the request charge reduces. I am reaching out to product team on the same and will get back at the earliest.

0 Votes 0 ·