[Solved] Cassandra one CqlSession shared in 40 threads sometime CQL return empty no record

How to optimize this SQL query?

In case you have your own slow SQL query, you can optimize it automatically here.

For the query above, the following recommendations will be helpful as part of the SQL tuning process.
You'll find 3 sections below:

  1. Description of the steps you can take to speed up the query.
  2. The optimal indexes for this query, which you can copy and create in your database.
  3. An automatically re-written query you can copy and execute in your database.
The optimization process and recommendations:
  1. Create Optimal Indexes (modified query below): The recommended indexes are an integral part of this optimization effort and should be created before testing the execution duration of the optimized query.
Optimal indexes for this query:
ALTER TABLE `lp_intervals_2021` ADD INDEX `lp_2021_idx_channel_id_interval_time` (`channel_id`,`interval_end_time`);
The optimized query:
SELECT
        mudr.lp_intervals_2021.channel_id,
        mudr.lp_intervals_2021.interval_end_time,
        mudr.lp_intervals_2021.flags,
        mudr.lp_intervals_2021.lp_value,
        mudr.lp_intervals_2021.validation_status,
        mudr.lp_intervals_2021.version_start_time 
    FROM
        mudr.lp_intervals_2021 
    WHERE
        mudr.lp_intervals_2021.channel_id IN (
            4040239, 4040245, 4040852, 15008307, 15008311, 15008312, 15004568, 15004571, 15004575, 9534062, 9534066, 9534067, 9519301, 9520004, 9520006, 15034324, 15034325, 15034327, 3983465, 3983470, 3983475, 25789081, 25789084, 25789088, 25818675, 25818677, 25818681, 22401049, 22401602, 22401603
        ) 
        AND mudr.lp_intervals_2021.interval_end_time > '2021-05-01 00:00:00+0800' 
        AND mudr.lp_intervals_2021.interval_end_time <= '2021-05-02 00:00:00+0800'

Related Articles



* original question posted on StackOverflow here.