#21843·arangodb

Incorrect sort when using inverted index

Author: fqriousCreated Jul 7, 2025Updated Jun 24, 2026
Labels1 Bug3 AQL3 Optimizer3 Index

Query Without Index

sql
FOR doc IN nvd_cve_vertex_collection //OPTIONS {indexHint: "cve_search_inv", forceIndexHint: true}
FILTER doc.type == 'vulnerability' AND doc._is_latest == TRUE

SORT doc.name ASC
LIMIT 10
RETURN doc.name

Response without index (correctly sorted)

json
[
  "CVE-2010-10011",
  "CVE-2016-20021",
  "CVE-2020-1818",
  "CVE-2020-1819",
  "CVE-2020-1820",
  "CVE-2020-1821",
  "CVE-2020-1822",
  "CVE-2020-1823",
  "CVE-2020-1824",
  "CVE-2020-9080"
]

Query With Index

sql
FOR doc IN nvd_cve_vertex_collection OPTIONS {indexHint: "cve_search_inv", forceIndexHint: true}
FILTER doc.type == 'vulnerability' AND doc._is_latest == TRUE

SORT doc.name ASC
LIMIT 10
RETURN doc.name

Response with index (incorrectly sorted)

json
[
  "CVE-2022-48619",
  "CVE-2023-5356",
  "CVE-2023-49259",
  "CVE-2023-28897",
  "CVE-2023-49262",
  "CVE-2023-28898",
  "CVE-2024-21611",
  "CVE-2024-21607",
  "CVE-2023-49647",
  "CVE-2023-46805"
]

The Index's Definition

json
{
  "analyzer": "identity",
  "cleanupIntervalStep": 2,
  "commitIntervalMsec": 1000,
  "consolidationIntervalMsec": 1000,
  "consolidationPolicy": {
    "type": "tier",
    "segmentsBytesFloor": 2097152,
    "segmentsBytesMax": 5368709120,
    "segmentsMax": 10,
    "segmentsMin": 1,
    "minScore": 0
  },
  "features": [
    "frequency",
    "norm"
  ],
  "fields": [
    {
      "name": "name"
    },
    {
      "name": "id"
    },
    {
      "name": "modified"
    },
    {
      "name": "created"
    },
    {
      "features": [],
      "analyzer": "norm_en",
      "name": "description"
    },
    {
      "name": "type"
    },
    {
      "name": "_cvss_base_score"
    },
    {
      "name": "_epss_score"
    },
    {
      "name": "_epss_percentile"
    },
    {
      "name": "_is_latest"
    }
  ],
  "figures": {
    "numDocs": 3607,
    "numPrimaryDocs": 3607,
    "numLiveDocs": 3607,
    "numSegments": 1,
    "numFiles": 6,
    "indexSize": 2114732
  },
  "id": "nvd_cve_vertex_collection/5669644",
  "includeAllFields": false,
  "name": "cve_search_inv",
  "primarySort": {
    "fields": [],
    "compression": "lz4"
  },
  "searchField": false,
  "sparse": true,
  "storedValues": [
    {
      "fields": [
        "external_references"
      ],
      "compression": "lz4"
    }
  ],
  "trackListPositions": false,
  "type": "inverted",
  "unique": false,
  "version": 1,
  "writebufferActive": 0,
  "writebufferIdle": 64,
  "writebufferSizeMax": 33554432
}

steps to reproduce

  • create a collection, call it nvd_cve_vertex_collection
  • create index, with the above json
  • upload this file test-vertices.json to the collection
  • test the queries