|
28 | 28 |
|
29 | 29 | import com.datastax.driver.core.ResultSet;
|
30 | 30 | import org.apache.cassandra.index.sai.disk.format.Version;
|
| 31 | +import org.apache.cassandra.index.sai.plan.QueryController; |
31 | 32 | import org.apache.cassandra.metrics.CassandraMetricsRegistry;
|
32 | 33 |
|
33 | 34 | import static org.apache.cassandra.index.sai.metrics.TableQueryMetrics.TABLE_QUERY_METRIC_TYPE;
|
@@ -225,6 +226,11 @@ public void testKDTreeQueryMetricsWithSingleIndex()
|
225 | 226 | @Test
|
226 | 227 | public void testKDTreePostingsQueryMetricsWithSingleIndex()
|
227 | 228 | {
|
| 229 | + // Turn off the query optimizer. |
| 230 | + // We need to do this in order to remove unpredictability of query plans, so that we get consistent metrics. |
| 231 | + // We don't want the query optimizer to eliminate the use of indexes. |
| 232 | + QueryController.QUERY_OPT_LEVEL = 0; |
| 233 | + |
228 | 234 | String table = "test_kdtree_postings_metrics_through_write_lifecycle";
|
229 | 235 | String v1Index = "test_kdtree_postings_metrics_through_write_lifecycle_v1_index";
|
230 | 236 | String v2Index = "test_kdtree_postings_metrics_through_write_lifecycle_v2_index";
|
@@ -255,13 +261,20 @@ public void testKDTreePostingsQueryMetricsWithSingleIndex()
|
255 | 261 | assertEquals(rowsWritten, actualRows);
|
256 | 262 |
|
257 | 263 | assertTrue(((Number) getMetricValue(objectName("NumPostings", keyspace, table, v1Index, "KDTreePostings"))).longValue() > 0);
|
| 264 | + waitForHistogramCountEquals(objectNameNoIndex("KDTreePostingsNumPostings", keyspace, table, PER_QUERY_METRIC_TYPE), 1); |
| 265 | + waitForHistogramMeanBetween(objectNameNoIndex("KDTreePostingsNumPostings", keyspace, table, PER_QUERY_METRIC_TYPE), 1.0, 1.0); |
258 | 266 |
|
259 |
| - waitForVerifyHistogram(objectNameNoIndex("KDTreePostingsNumPostings", keyspace, table, PER_QUERY_METRIC_TYPE), 1); |
| 267 | + // the query performed no skips, but the metric should be updated because the index was used, so we should get |
| 268 | + // a single entry in the histogram with 0 skips |
| 269 | + waitForHistogramCountEquals(objectNameNoIndex("KDTreePostingsSkips", keyspace, table, PER_QUERY_METRIC_TYPE), 1); |
| 270 | + waitForHistogramMeanBetween(objectNameNoIndex("KDTreePostingsSkips", keyspace, table, PER_QUERY_METRIC_TYPE), 0.0, 0.0); |
260 | 271 |
|
261 |
| - // V2 index is very selective, so it should lead the union merge process, causing V1 index to be not used at all. |
262 |
| - execute("SELECT id1 FROM " + keyspace + "." + table + " WHERE v1 >= 0 AND v1 <= 1000 AND v2 = '5' ALLOW FILTERING"); |
| 272 | + // V2 index is very selective, so it should lead the union merge process, causing V1 index to skip/advance |
| 273 | + execute("SELECT id1 FROM " + keyspace + "." + table + " WHERE v1 >= 0 AND v1 <= 1000 AND v2 IN ('5', '10', '20', '22') ALLOW FILTERING"); |
263 | 274 |
|
264 |
| - waitForVerifyHistogram(objectNameNoIndex("KDTreePostingsSkips", keyspace, table, PER_QUERY_METRIC_TYPE), 2); |
| 275 | + // we expect exactly 4 skips from this query, but the mean will be 2.0 because of the previous query which had 0 skips |
| 276 | + waitForHistogramCountEquals(objectNameNoIndex("KDTreePostingsSkips", keyspace, table, PER_QUERY_METRIC_TYPE), 2); |
| 277 | + waitForHistogramMeanBetween(objectNameNoIndex("KDTreePostingsSkips", keyspace, table, PER_QUERY_METRIC_TYPE), 1.99, 2.01); |
265 | 278 | }
|
266 | 279 |
|
267 | 280 | @Test
|
@@ -353,7 +366,7 @@ public void testKDTreePartitionsReadAndRowsFiltered()
|
353 | 366 |
|
354 | 367 | //TODO This needs revisiting with STAR-903 because we are now reading rows one at a time
|
355 | 368 | waitForEquals(objectNameNoIndex("TotalPartitionReads", keyspace, table, TABLE_QUERY_METRIC_TYPE), Version.current() == Version.AA ? 2 : 3);
|
356 |
| - waitForVerifyHistogram(objectNameNoIndex("RowsFiltered", keyspace, table, PER_QUERY_METRIC_TYPE), 1); |
| 369 | + waitForHistogramCountEquals(objectNameNoIndex("RowsFiltered", keyspace, table, PER_QUERY_METRIC_TYPE), 1); |
357 | 370 | waitForEquals(objectNameNoIndex("TotalRowsFiltered", keyspace, table, TABLE_QUERY_METRIC_TYPE), 3);
|
358 | 371 | }
|
359 | 372 |
|
|
0 commit comments