This is a question about how to query in SQL with large number of data.
According to your description, we can use database index to improve the performance of query.
We can create an index in the keyword field and use T-SQL as below:
Select count(1) From T Where Keyword = XXX
In this way, the database engine will use index instead of full table scan.
In Azure SQL Db, we can create index using T-SQL: CREATE INDEX (Transact-SQL)
We can also use SSMS to create index, more information about index in Azure SQL Db, we can refer to: Clustered and Nonclustered Indexes Described
Here are some optimization methods for database query for you, hope it will be help:
1. To optimize the query, avoid full table scanning as much as possible, and first consider indexing the columns involved in where and order by.
2. The null value judgment of the field in the where clause should be avoided as far as possible. Otherwise, it will cause the engine to abandon the index and scan the whole table, such as:
Select id from t where num is null
You can set a default value of 0 on num to ensure that there is no null value in the num column in the table.
Select id from t where num=0
3. try to avoid using "=" or "> operator in the where clause, otherwise the engine will discard the index and perform the full table scan.
4. Use or to join conditions in where clauses should be avoided as far as possible, otherwise it will cause the engine to abandon the use of the index and perform a full table scan, such as:
Select id from t where num=10 or num=20
It can be inquired like this:
Select id from t where num=10
Union all
Select id from t where num=20
5.in and not in should also be used with caution, otherwise the whole table will be scanned, such as:
Select id from t where num in (1,2,3)
For continuous values, use between instead of in:
Select id from t where num between 1 and 3
The query under
6. will also result in full table scan:
Select id from t where name like'%abc%'
In order to improve the efficiency, the full text retrieval can be considered.