|
| 1 | +--- |
| 2 | +title: Indexing in Azure Cosmos DB Cassandra API account |
| 3 | +description: Learn how secondary indexing works in Azure Azure Cosmos DB Cassandra API account. |
| 4 | +author: TheovanKraay |
| 5 | +ms.service: cosmos-db |
| 6 | +ms.topic: conceptual |
| 7 | +ms.date: 04/04/2020 |
| 8 | +ms.author: thvankra |
| 9 | +ms.reviewer: sngun |
| 10 | +--- |
| 11 | + |
1 | 12 | # Secondary indexing in Azure Cosmos DB Cassandra API
|
2 | 13 |
|
3 |
| -The Cassandra API in Azure Cosmos DB leverages the underlying Indexing infrastructure to expose the indexing strength that is inherent in the platform. Cassandra API in Azure Cosmos DB supports secondary indexing to create an index on certain attributes. In general, it's not advised to use Apache Cassandra to execute filter queries on the columns that aren't partitioned. You must use ALLOW FILTERING syntax explicitly which, results in a less performant operation. However, in Azure CosmosDB you can run such queries on low cardinality attributes because they fan out across partitions to retrieve the results. |
| 14 | +The Cassandra API in Azure Cosmos DB leverages the underlying indexing infrastructure to expose the indexing strength that is inherent in the platform. However, unlike the core SQL API, Cassandra API in Azure Cosmos DB does not index all attributes by default. Instead, it supports secondary indexing to create an index on certain attributes, which behaves the same way as Apache Cassandra. |
| 15 | + |
| 16 | +In general, it's not advised to execute filter queries on the columns that aren't partitioned. You must use ALLOW FILTERING syntax explicitly, which results in an operation that may not perform well. In Azure Cosmos DB you can run such queries on low cardinality attributes because they fan out across partitions to retrieve the results. |
4 | 17 |
|
5 | 18 | It's not advised to create an index on a frequently updated column. It is prudent to create an index when you define the table. This ensures that data and indexes are in a consistent state. In case you create a new index on the existing data, currently, you can't track the index progress change for the table. If you need to track the progress for this operation, you have to request the progress change via a [support ticket]( https://docs.microsoft.com/azure/azure-portal/supportability/how-to-create-azure-support-request).
|
6 | 19 |
|
7 |
| -If you are trying to create a new index on existing data, tracking the index progress change for a table is not exposed. If you need to track the progress - please request the progress change via a support ticket. |
| 20 | + |
| 21 | +> [!NOTE] |
| 22 | +> Secondary index is not supported on the following objects: |
| 23 | +> - data types such as frozen collection types, decimal, and variant types. |
| 24 | +> - Static columns |
| 25 | +> - Clustering keys |
8 | 26 |
|
9 | 27 | ## Indexing example
|
10 | 28 |
|
@@ -34,28 +52,20 @@ If you try executing the following statement, you will run into an error that as
|
34 | 52 | select user_id, lastname from sampleks.t1 where lastname='nishu';
|
35 | 53 | ```
|
36 | 54 |
|
37 |
| -Although the Cassandra API supports ALLOW FILTERING as mentioned in the previous section, however, it's not recommended. You should instead create an index in the as shown in the following example: |
| 55 | +Although the Cassandra API supports ALLOW FILTERING, as mentioned in the previous section, it's not recommended. You should instead create an index in the as shown in the following example: |
38 | 56 |
|
39 | 57 | ```shell
|
40 | 58 | CREATE INDEX ON sampleks.t1 (lastname);
|
41 | 59 | ```
|
42 | 60 | After creating an index on the "lastname" field, you can now run the previous query successfully. With Cassandra API in Azure Cosmos DB, you do not have to provide an index name. A default index with format `tablename_columnname_idx` is used. For example, ` t1_lastname_idx` is the index name for the previous table.
|
43 | 61 |
|
44 | 62 | ## Dropping the index
|
45 |
| -You need to know the index name is to drop the index. Run the `desc schema` command to get the description of your table. The output of this command includes the index name in the format `CREATE INDEX tablename_columnname_idx ON keyspacename.tablename(columnname)'. You can then use the index name to drop the index as shown in the following example: |
46 |
| -
|
47 |
| -``` |
48 |
| -CREATE INDEX tablename_columnname_idx ON keyspacename.tablename(columnname) |
49 |
| -``` |
50 |
| -
|
51 |
| -Use the index name to drop the index as below; |
| 63 | +You need to know what the index name is to drop the index. Run the `desc schema` command to get the description of your table. The output of this command includes the index name in the format `CREATE INDEX tablename_columnname_idx ON keyspacename.tablename(columnname)`. You can then use the index name to drop the index as shown in the following example: |
52 | 64 |
|
53 | 65 | ```shell
|
54 | 66 | drop index sampleks.t1_lastname_idx;
|
55 | 67 | ```
|
56 | 68 |
|
57 |
| -### Note |
58 |
| -Secondary index in not supported on: |
59 |
| - - Data types like frozen collection types, decimal and variant types. |
60 |
| - - Static |
61 |
| - - Clustering keys |
| 69 | +## Next steps |
| 70 | +* Learn how [automatic indexing](index-overview.md) works in Azure Cosmos DB |
| 71 | +* [Apache Cassandra features supported by Azure Cosmos DB Cassandra API](cassandra-support.md) |
0 commit comments