mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-02-09 15:27:11 +00:00
lib/storage: use composite indexes (metricName, label=value) when searching for matching time series at /api/v1/labels, /api/v1/label/.../values and /api/v1/status/tsdb
This should improve query performance when match[], extra_filters[] or extra_label args are passed to these APIs Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5055
This commit is contained in:
parent
1348a822f8
commit
293f03f2dd
1 changed files with 16 additions and 0 deletions
|
@ -592,6 +592,11 @@ func (db *indexDB) SearchLabelNamesWithFiltersOnTimeRange(qt *querytracer.Tracer
|
|||
maxLabelNames, maxMetrics int, deadline uint64) ([]string, error) {
|
||||
qt = qt.NewChild("search for label names: filters=%s, timeRange=%s, maxLabelNames=%d, maxMetrics=%d", tfss, &tr, maxLabelNames, maxMetrics)
|
||||
defer qt.Done()
|
||||
|
||||
if tr.MinTimestamp >= db.s.minTimestampForCompositeIndex {
|
||||
tfss = convertToCompositeTagFilterss(tfss)
|
||||
}
|
||||
|
||||
lns := make(map[string]struct{})
|
||||
qtChild := qt.NewChild("search for label names in the current indexdb")
|
||||
is := db.getIndexSearch(accountID, projectID, deadline)
|
||||
|
@ -910,6 +915,11 @@ func (db *indexDB) SearchLabelValuesWithFiltersOnTimeRange(qt *querytracer.Trace
|
|||
maxLabelValues, maxMetrics int, deadline uint64) ([]string, error) {
|
||||
qt = qt.NewChild("search for label values: labelName=%q, filters=%s, timeRange=%s, maxLabelNames=%d, maxMetrics=%d", labelName, tfss, &tr, maxLabelValues, maxMetrics)
|
||||
defer qt.Done()
|
||||
|
||||
if tr.MinTimestamp >= db.s.minTimestampForCompositeIndex {
|
||||
tfss = convertToCompositeTagFilterss(tfss)
|
||||
}
|
||||
|
||||
lvs := make(map[string]struct{})
|
||||
qtChild := qt.NewChild("search for label values in the current indexdb")
|
||||
is := db.getIndexSearch(accountID, projectID, deadline)
|
||||
|
@ -1326,6 +1336,11 @@ func (is *indexSearch) getSeriesCount() (uint64, error) {
|
|||
// GetTSDBStatus returns topN entries for tsdb status for the given tfss, date and focusLabel.
|
||||
func (db *indexDB) GetTSDBStatus(qt *querytracer.Tracer, accountID, projectID uint32, tfss []*TagFilters, date uint64, focusLabel string, topN, maxMetrics int, deadline uint64) (*TSDBStatus, error) {
|
||||
qtChild := qt.NewChild("collect tsdb stats in the current indexdb")
|
||||
|
||||
if int64(date*msecPerDay) >= db.s.minTimestampForCompositeIndex {
|
||||
tfss = convertToCompositeTagFilterss(tfss)
|
||||
}
|
||||
|
||||
is := db.getIndexSearch(accountID, projectID, deadline)
|
||||
status, err := is.getTSDBStatus(qtChild, tfss, date, focusLabel, topN, maxMetrics)
|
||||
qtChild.Done()
|
||||
|
@ -1630,6 +1645,7 @@ func (db *indexDB) DeleteTSIDs(qt *querytracer.Tracer, tfss []*TagFilters) (int,
|
|||
if len(tfss) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
tfss = convertToCompositeTagFilterss(tfss)
|
||||
|
||||
// Obtain metricIDs to delete.
|
||||
tr := TimeRange{
|
||||
|
|
Loading…
Reference in a new issue