Repository navigation
Read a mixed index of the order keys which answers a query whole - #5125
Merged
porunov merged 1 commit intoOct 24, 2026
Merged
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
Cross-backend ordering, custom index selection, and result-visibility changes warrant final human validation despite extensive regression coverage.
No open issues 🎉
What changed in this PR
Addresses #5124 by allowing ordered traversals to use a single mixed index that covers all order keys and conditions, avoiding full scans when eligible.
Changes:
- Adds fallback index selection using order-key presence conditions, with safeguards for unsupported sorting and custom strategy choices.
- Adds regression coverage for index selection, ordering, transaction changes, aggregations, and
query.force-index. - Documents eligibility rules, performance tradeoffs, and changes in index-backed result visibility.
| File | Description |
|---|---|
| janusgraph-es/src/test/java/org/janusgraph/diskstorage/es/ElasticsearchJanusGraphIndexTest.java | Tests scan fallback for string analyzers and custom mappings. |
| janusgraph-core/src/main/java/org/janusgraph/graphdb/query/graph/GraphCentricQueryBuilder.java | Adds guarded fallback selection of a fully covering mixed index. |
| janusgraph-backend-testutils/src/main/java/org/janusgraph/graphdb/JanusGraphIndexTest.java | Adds shared regression tests and updates index-use expectations. |
| janusgraph-backend-testutils/src/main/java/org/janusgraph/graphdb/CandidateIgnoringIndexSelectionStrategy.java | Adds a test strategy that selects outside supplied candidates. |
| docs/schema/index-management/index-performance.md | Explains when ordered traversals use mixed indexes or scans. |
| docs/changelog.md | Records behavior, performance, and visibility changes. |
Review effort: Balanced
Fixes JanusGraph#5124 Since JanusGraph#5108, a traversal's order().by(key) requires a value of the key, so g.V().order().by("name").limit(10) returns what g.V().has("name").order().by("name").limit(10) returns. The second reads the mixed index which holds name with an exists query, sorted by the index, and stops after the first hits. The first has no condition which an index answers, so it read every vertex and sorted them in memory, which fails with a QueryException from a million vertices on, and which query.force-index refused as a full scan. So did g.V().hasLabel("person").order().by("name").limit(10) with an index of the persons, and an order of edges by a key of an edge mixed index. The presence of the order keys joined the query's condition only after the index selection strategy had chosen the indexes for the other conditions, so that it would not add a mixed index next to one which answers them, which a joint query reads whole. Where the strategy chooses no index for the query's own conditions, it now chooses again for those conditions together with the presence of a value of each order key, among the mixed indexes of the result type which may answer them, as its own candidates, and which sort the elements by the query's order: which hold every order key, which their backend sorts by as JanusGraph orders its values, a key of several values included (IndexSelectionUtil.indexCoversOrder, which asks each backend since JanusGraph#5121), and none of them with custom parameters, which Elasticsearch takes into its mapping, so that they may keep it from sorting by the key. The brute-force strategy, which the default one takes up to query.index-select-threshold candidates, weighs an index which holds a key as a text, which no backend sorts by, as one which holds it as a string: left among the candidates, such an index would be taken in place of one which holds the key as a string, by chance, where both answer the query alike. The approximate strategy prefers the one which sorts, by indexCoversOrder. The query takes that choice where it is a single index which covers every condition: a mixed index which holds every order key and answers the query whole, as it answers a has(key). It takes it only where the index is one of the candidates, as nothing keeps a strategy from taking another one. The query is then fitted, and sorted where the index sorts by the query's order, as it does with JanusGraph's strategies (sortedOnlyWhereTheIndexSorts checks it), so that a limit reads only the first hits, and a count() or an aggregation of a key of the index right after the order comes from the index. The strategies decide as for a has(key) whether a mixed index covers such a condition, by the status of the key's field and IndexSerializer.supportsExistsQuery, and take an index restricted to a label only for a query of that label, whose condition the index then covers too. Any other query reads every element as before. One whose index would leave a condition to be checked in memory would read the index in growing batches and look each element up, and a joint query of several indexes reads all but the first whole: every element with a value of their keys. An or() alone still runs each of its branches as a query of its own where no index covers it in the first choice, as none covers it in the second either. A query of JanusGraph's API, which keeps the elements without the key, is unaffected. Signed-off-by: Oleksandr Porunov <alexandr.porunov@gmail.com> Co-authored-by: Oleksandr Porunov <alexandr.porunov@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
porunov
force-pushed
the
order-by-key-reads-its-mixed-index
branch
from
October 23, 2026 21:02
73ac4a0 to
fbce7da
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5124
Merge after #5127, which reads a Solr result larger than a page in pages which grow up to
index.[X].solr.max-page-size, rather than in pages of 50 at growing offsets: the Cost note below has the figures.Since #5108, a traversal's
order().by(key)leaves out the elements which have no value of the key, sog.V().order().by('name').limit(10)returns whatg.V().has('name').order().by('name').limit(10)returns. JanusGraph answers the second from the mixed index which holdsname, sorted by the index, and reads only the first hits. It answered the first, which has no condition that an index answers, by reading every vertex and sorting them in memory. That fails with aQueryExceptionfrom a million vertices on, andquery.force-indexrefuses it as a full scan. So didg.V().hasLabel('person').order().by('name').limit(10)with an index of the persons which holdsname, and an order of edges by a key of an edge mixed index.Such a traversal now reads a single mixed index which holds every order key, which its backend sorts by, and answers every condition, as
has(key)does: fitted, and, with JanusGraph's index selection strategies, sorted by the index, so that a limit reads only the first hits. Every other traversal reads what it read before.Changes
GraphCentricQueryBuilder.constructQueryWithoutProfile: where the index selection strategy chooses no index for the query's own conditions, and the query requires the values of its order keys (requireOrderValues(), whichJanusGraphStepcalls), the strategy chooses again for those conditions together with the presence of a value of each order key,PredicateCondition(key, Cmp.NOT_EQUAL, null).Candidates (
sortingIndexes): the builder passes the strategy'sselectIndices(Set<IndexType> indexCandidates, …)the mixed indexes of the result type which hold a key of a condition (IndexSelectionUtil.getMatchingIndexes, asAbstractIndexSelectionStrategy.createIndexRawCandidatesfinds a strategy's own candidates), and which sort the elements by the query's order:IndexSelectionUtil.indexCoversOrder, which asks each backend throughIndexSerializer.supportsOrderingsince Sort in memory the orders by keys which the index backend can't sort #5121): no backend sorts by a string which the index maps asTEXT, as a mixed index maps a string by default, Elasticsearch doesn't by a string with astring-analyzer, and Lucene doesn't by aUUID, nor by a key ofLISTorSETcardinality;holdsNoOrderKeyWithCustomParameters), which Elasticsearch takes into its mapping, and which may keep it from sorting by the key, asdoc_valuesfalse does:supportsOrderingdoesn't look at them.The brute-force strategy, the default's choice up to
query.index-select-thresholdcandidates, weighs an index which holds a key as aTEXTas one which holds it as aSTRING, and breaks the tie by the order of aHashSetof newIndexCandidates, which differs from one query to the next: left among the candidates, theTEXTindex would be taken in place of one which holds the key as aSTRINGor aTEXTSTRING, by chance, where both answer the query alike. The approximate strategy, the default's choice beyond that threshold, prefers the one which sorts, as it scores an index which covers the order higher (ORDER_MATCH), byindexCoversOrder, which askssupportsOrderingsince Sort in memory the orders by keys which the index backend can't sort #5121. An index which holds only some of the order keys isn't a candidate, as no such index could be the single one which answers the query. The composite indexes which a strategy's own candidates hold are left out too: they can't answer the presence of a key, so that a choice with one isn't a single index which covers every condition. The filter ofcreateIndexRawCandidatesfor anor()alone doesn't apply, as these conditions are a conjunction.The query takes that choice where it is a single index which covers every condition (
coveredWithValues.size() == withValues.numChildren()), and so a mixed index which holds every order key and answers the query whole, and where that index is one of the candidates (candidates.contains(…)):IndexSelectionStrategydoesn't promise to choose among them, and a strategy which takes another index may take one which can't sort by the order keys, whose every hit JanusGraph would then read and sort, or one which holds a key with custom parameters, which the index is given the order by and may fail on, as Elasticsearch fails withCould not call indexondoc_valuesfalse. Such a choice leaves the order to the scan, so that every second choice is one which the index can sort.sortedOnlyWhereTheIndexSortschecks it), so that a limit reads only the first hits. A strategy which gives the index only part of the order, as the test'sPartialOrderIndexSelectionStrategydoes, gets a fitted choice which the index doesn't sort, and JanusGraph sorts its hits itself, with the right results.count()right after the order, or amin(),max(),sum()ormean()of a key which the index holds, comes from the index (JanusGraphMixedIndexCountStrategyandJanusGraphMixedIndexAggStrategy), as after ahas().has(key), whether a mixed index covers such a condition (AbstractIndexSelectionStrategy.coversAll: anENABLEDfield of the key, andIndexSerializer.supportsExistsQuery), and take an index restricted to a label only for a query of that label, whose condition the index then covers too.A custom strategy keeps its choice among the candidates, as the test strategy which gives the index only part of the order does through that method. For this choice, it loses an override of
createIndexRawCandidatesand any override ofselectIndices(ElementCategory resultType, …): the builder doesn't call them, and gives the candidates itself. A choice of an index which isn't among them is refused, as above.requireValues).has('tag', 't'), or the label ofhasLabel('person')for an index which isn't restricted to persons. The query would read the index in growing batches, looking each element up to check the condition, up to every element with a value of the order keys where few hold the condition; the scan reads every element once, in the storage backend's order.g.V().hasLabel('person').order().by('nick').by('name'), withnickin an index of the persons andnamein another one, has none, and with both in an index which isn't restricted to persons next to the index of the persons, only the first, which leaves the label to JanusGraph. Two candidates still answer a query only together where each covers the presence of some of the keys alone, as where each holds one of them in a field which isn'tENABLED, and a custom strategy may take several of them. A joint query streams its first subquery and reads every other one whole:StandardJanusGraphTx's executor passesQuery.NO_LIMITtoQueryUtil.processIntersectingRetrievals, which collects each into a list. A single mixed index which holds every order key, restricted to the traversal's label where it has one, answers such an order.or()alone:JanusGraphStepruns each of its branches as a query of its own where no index answers theor()whole, and each branch chooses again itself. No index covers theor()in the second choice where none covers it in the first, so that split stays as it was, and each branch takes the second choice on its own where a single mixed index answers it whole. Severalor()steps make a conjunction, whichJanusGraphStepruns as a single query, and which takes the second choice as a whole where a single mixed index answers each of them.UUIDon Lucene, or of edges by a key ofLISTorSETcardinality on Lucene, which now keeps the scan.requireOrderValues().requireOrderValues()'s Javadoc says where the presence conditions take part in choosing the indexes.has(key)sees, as an index does, rather than what the storage backend holds, both ways; that on Elasticsearch such a traversal without a limit reads every hit in pages ofmax-result-set-size, and on Solr in the growing pages of Read Solr results larger than a page in growing pages #5127's section; and Orders by a key of several values now points to it where a mixed index holds the key.Tests
JanusGraphIndexTest.testOrderReadsAMixedIndexOfItsKeysWhereNoIndexAnswersTheConditions(every index backend; the mixed indexes are namedmixed,verticesandedges, which the Solr test container creates). Persons, organizations and other vertices, most of them without aname, anage, anickor atag, and edges between them, some without aweight, are written into the graph and into a TinkerGraph.mixedholds the names, ages and ckinds of every vertex,verticesthe nicks of the persons only (indexOnly),edgesthe weights. Composite indexes holdckind, which a query of ackindreads rather thanmixed, anduid. No index holdstag. Twenty-eight traversals return the same from both:name, ascending and descending, with limits and a range, and acount()after the order;ageandname, whichmixedholds, the second ordering the ties of the first;nameandtag, which no index holds;tag, byweight, which only the index of edges holds, and bynickwithout the label, and of persons and organizations, or organizations only, bynick;nick, whichverticesanswers whole, also with acount(), byname, whichmixedanswers but for the label, and bynickandname, which only both indexes together hold;has('tag')andhas('tag', gt('t3')), which no index answers;has('ckind', 'p'),has('ckind', within('p', 'q')), andor(has('ckind', 'p'), has('uid', 8));or(has('tag', gt('t5')), has('ckind', 'q')), of which no index answers the first branch, and one next to twoor()steps which no index answers;weight, also of the labellinkwith acount().They return the same again in a transaction which adds a person, an organization and another vertex, gives a vertex a name and takes another one's, changes a name and a nick, takes a nick, removes a vertex, and adds an edge, removes one, changes a weight, takes one and gives one. A new transaction's profiles show:
[(name <> null)][ASC(name)]:mixed, fitted and sorted, fororder().by('name').limit(3),[DESC(name)]descending, and[(age <> null AND name <> null)][ASC(age), ASC(name)]:mixedfor the two keys;[(nick <> null)][ASC(nick)]:vertices, fitted and sorted, for the persons bynick;[(weight <> null)][ASC(weight)]:edges, fitted and sorted, for the edges;JanusGraphMixedIndexAggStep) fororder().by('name').count(), and fororder().by('name').values('age')andmin(),max(),sum()andmean(), which return what the TinkerGraph returns;mixedwould leave a condition to JanusGraph: for the order bynameandtag, the persons byname, andhas('tag')byname;nickandname, for the orders bytag, byweightand bynickwithout the label, and for organizations or persons and organizations bynick;has('ckind', 'p')andwithin, and for each of the two branches of theor(), which run as queries of their own;has('tag', gt('t5')), which no index answers, and the composite index for the other branch, and a full scan for the twoor()steps, which make a single query.JanusGraphIndexTest.testForceIndexAllowsAnOrderWhichAMixedIndexOfItsKeysAnswers(every index backend): withquery.force-index, six traversals which a mixed index answers, or a composite one, return what the TinkerGraph returns, and four which read every vertex,has('tag').order().by('name')among them, fail withCould not find a suitable index.JanusGraphIndexTest.testOrderReadsAMixedIndexOfItsKeysOnlyWhereItsBackendSortsByThem(every index backend).mixedholds aname, atextwith the default mapping,wordsmapped asTEXT, atitlemapped asTEXTSTRING, ananalyzedstring mapped asSTRINGwith astring-analyzer, and aUUIDcode, and gets arankadded after the vertices were written, which isn'tENABLED.verticesholdsrankand getsnameadded in the same way, so that only the two indexes together answer the presence of both. Six orders bytext,words,nameandtext,rankandname, andnameandrankreturn what a TinkerGraph returns, by a full scan; the texts' least words don't order them as their strings do, as Solr would. Orders byname, and bytitleascending and descending, readmixed, sorted, and return what the TinkerGraph returns:Mango,apple,x a, which neither the titles' lower case nor their least words order so. The orders byanalyzedand bycodereadmixed, sorted, where its backend sorts by the key, as the graph'sIndexSerializer.supportsOrderingtells, and every vertex otherwise: Lucene and Solr read it foranalyzed, which Elasticsearch scans for, and Elasticsearch and Solr forcode, which Lucene scans for. The codes, of which the first digit of either half is from8up or below it, come in the order of their string forms, as JanusGraph orders UUIDs, which isn't TinkerPop'sUUID.compareToorder.JanusGraphIndexTest.testOrderByAKeyOfTwoMixedIndexesReadsTheOneWhichSortsByIt(every index backend):mixedholdsnameas aTEXT, andverticesas aSTRING, both of every vertex.mixedis built first, and its name sorts first, so that a strategy which broke the tie by either order would take it every time, and the default's brute-force choice would take it now and then. Twenty times,order().by('name').limit(3)is built anew, returns what a TinkerGraph returns, and readsvertices, fitted and sorted.JanusGraphIndexTest.testOrderReadsEveryElementWhereTheStrategyTakesAnIndexOutsideItsCandidates(every index backend): the same indexes, withCandidateIgnoringIndexSelectionStrategy, a test strategy which chooses among the indexes that match the conditions other than its candidates, where there are any, as one which collects indexes of its own might. It takesmixed, which the builder refuses:order().by('name').limit(3)returns what a TinkerGraph returns, by a full scan.ElasticsearchJanusGraphIndexTest.testOrderByAKeyWhichElasticsearchMayNotSortByReadsEveryElement(Elasticsearch): orders by aSTRINGkey and aTEXTSTRINGkey with astring-analyzer, and by aSTRINGkey with the custom parameterdoc_valuesfalse, ascending and descending, also after aSTRINGkey which Elasticsearch sorts by, return their values in order, by a full scan.JanusGraphIndexTest.testOrderingListProperty(from List property ordering - utilize mixed index #4860) expectedg.V().order().by('name1')to read every vertex. It now readslistPropertyOrderingwith(name1 <> null), sorted, and so doesg.V().order().by('name2'), of aLISTkey, on Elasticsearch and Solr.JanusGraphIndexTest.testResultsWhichAStrategyHoldsSortedByAnIndexGivenPartOfTheOrderAreSortedInMemory(from Order by a key of several values as the indexes do #5102):V().order().by('name').by('age'), which the second choice answers, returns the ages in order, ascending and descending, under the strategy which gives the index only the first key of the order.JanusGraphIndexTest.testOrderOfEdgesByAKeyDeclaredToHoldSeveralValues(from Order by a key of several values as the indexes do #5102):g.E().order().by('weights'), of aLISTkey, without a condition, returns the weights in order, ascending and descending, and readsedges, sorted, on Elasticsearch and Solr, which sort by a key of several values, and every edge on Lucene, which doesn't.Mutations, each reverting or breaking one part of the change, are all caught (20, all run with Lucene; the two which only Elasticsearch catches with Elasticsearch 9.5.4 too; and those which drop
indexCoversOrderfrom the filter, drop its check ofsupportsOrdering, drop the check of the candidates, or check the choice afterwards, with Elasticsearch and with Solr in the JVM too):GraphCentricQueryBuilder, without the second choice: the profile oforder().by('name').limit(3)shows a full scan,[]for[(name <> null)][ASC(name)]:mixed, and so dotestOrderingListProperty's index check, the order bynameof the filter's test, and the test of the two indexes; underquery.force-index,Could not find a suitable index to answer graph query and graph scans are disabled: [(name <> null)]3(3):VERTEX.has('ckind', 'p')readsmixed, which then answers its condition and its order,mixedforbyCkind.query.force-index,has('tag').order().by('name')is no longer refused, and the persons bynamereadmixed,nullfor a full scan.order().by('rank').by('name')readsmixedandverticestogether, each of which answers the presence of one of the keys:nullfor a full scan whereverticescomes first in the joint query, and[4, 3, 2, 1]for[3, 1, 4, 2]wheremixeddoes, sorting by itsrank, which isn'tENABLED. So the rule of a single index keeps the order right, too.[(name <> null AND name <> null)][ASC(name)]:mixed; and so it is where a covered presence is narrowed again.isOrderedfalse.sortedOnlyWhereTheIndexSortson the second choice: under the strategy which gives the index only the first order key, the ties of the name come in the index's order, as[3, 1, 2, 0]for[1, 2, 3, 0].indexCoversOrderin the filter, with the check of custom parameters kept, or failing with aNullPointerExceptionon an index which lacks an order key: the orders bytextreadmixed,nullfor a full scan, the key of the two indexes readsmixedunsorted, for[(name <> null)][ASC(name)]:vertices, and under the strategy which takes an index outside its candidates, which then has none to take, the order reads an index rather than every element, on Lucene, Elasticsearch and Solr; on Lucene, the edges byweightsreadedges. The same failing with aNullPointerExceptionon an index which lacks an order key, no filter at all, or the strategy's own candidates in its place: caught alike, on Lucene.indexCoversOrderwithout its check ofIndexSerializer.supportsOrdering: the same failures but for the edges byweights, on Lucene, Elasticsearch and Solr.indexCoversOrderwithout its rule for keys of several values: on Lucene, the edges byweightsreadedges, unsorted,nullfor a full scan.Could not call indexon Elasticsearch for the order by the key withdoc_valuesfalse, alone or after aSTRINGkey.[]for[(name <> null)][ASC(name)]:vertices, on Lucene, Elasticsearch and Solr.mixed, which holdsnameas aTEXT, unsorted,nullfor a full scan, on Lucene, Elasticsearch and Solr.g.V().order().by('weight')reads the index of edges, and fails withIllegalArgumentException: Id must be either String or a positive long value.Three changes which shouldn't matter change no test's result: a check that the query isn't an
or()alone, the composite indexes kept among the candidates, and the filter applied to the strategy's choice afterwards as well. A single index which covers every condition covers the presence of each order key, which a composite index can't, and covers anor()alone only where the first choice did; and the choice is one of the candidates.On master
c29f6f365, with these tests, on Lucene:testOrderReadsAMixedIndexOfItsKeysWhereNoIndexAnswersTheConditionsreturns what TinkerGraph returns for its twenty-eight traversals, and then fails at its first profile check, a full scan:[]for[(name <> null)][ASC(name)]:mixed.testForceIndexAllowsAnOrderWhichAMixedIndexOfItsKeysAnswersfails withJanusGraphException: Could not find a suitable index to answer graph query and graph scans are disabled: [(name <> null)]3(3):VERTEX.testOrderReadsAMixedIndexOfItsKeysOnlyWhereItsBackendSortsByThempasses its six full scans, as master scans for every order, and fails where it expects the order bynameto read the index,[]for[(name <> null)][DESC(name)]:mixed.testOrderByAKeyOfTwoMixedIndexesReadsTheOneWhichSortsByItreturns what TinkerGraph returns, and fails where it expects the order to readvertices,[].testOrderingListPropertyfails its check thatg.V().order().by('name1')reads the index.testOrderReadsEveryElementWhereTheStrategyTakesAnIndexOutsideItsCandidatesandtestOrderOfEdgesByAKeyDeclaredToHoldSeveralValuespass, as master reads every element for those orders, and so doestestResultsWhichAStrategyHoldsSortedByAnIndexGivenPartOfTheOrderAreSortedInMemory, as master sorts that order in memory.The reproduction of the issue, run as a Java program with master's core and with this change's, gives the profiles and the
query.force-indexfailure which the issue quotes on master, and on this change[(name <> null)][ASC(name)](2):byName, fitted and sorted, also underquery.force-index. With 1,000,001 vertices, master failsg.V().order().by('name').limit(2)withQueryException: Could not execute query since pre-sorting requires fetching more than 1000000 elements. Consider rewriting the query to exploit sort orders, and this change returns the first two names.Locally, Java 11, on this change as it stands, rebased on master
c29f6f365, which has #5115, #5117, #5119, #5121 and #5123, with checkstyle (no violations):BerkeleyElasticsearchTestwhole passes (156, 1 skipped), with janusgraph-es's checkstyle.SolrRunner's MiniSolrCloud with BerkeleyJE asBerkeleySolrTestconfigures it,JanusGraphIndexTestwhole passes (143, 1 skipped). The repository'sjanusgraph-solr/src/test/resources/collections.txtlackslistPropertyOrdering, whichtestOrderingListPropertyneeds: the harness ran with a copy which adds it, as CI's container lists it inJanusGraphSolrContainer.COLLECTIONS.Notes
Cost. An A/B of
janusgraph-coreagainst masterc29f6f365, on an inmemory graph with its mixed indexes on Lucene, and in two more runs on Elasticsearch 9.5.4 and on Solr 9.10.1 in containers: 40,000 vertices, persons and organizations, a fifth of which lack aname, a fifth anage, a fifth anickand a fifth adescription, each drawn on its own, and 20,000 edges, a fifth without aweight. The mixed indexmixedholds every vertex'sname, mapped asSTRING, itsageand itsdescription, mapped asTEXTby default;peopleholds the persons'nick, mapped asSTRING, andedgesthe edges'weight; no index holdstag, which one vertex and one edge in a thousand have asrare, and none asnone. The Solr run has Read Solr results larger than a page in growing pages #5127'sjanusgraph-solron both sides, as the Solr paragraph below explains. Each group of traversals ran in JVMs of its own, three passes a side in alternating order, each figure the median of the passes' medians of three timed windows of 2 s after a warm-up, at 1 thread:g.V().order().by('name').limit(10)g.V().order().by('name', desc).limit(10)g.V().order().by('age').by('name').limit(10)g.V().order().by('name').range(100, 110)g.V().hasLabel('person').order().by('nick').limit(10)g.V().order().by('name').count()g.E().order().by('weight').limit(10)g.V().order().by('name').range(20000, 20010)g.V().order().by('name'), 31,846 verticesThe traversals which this change leaves as they were took as long as on master, from 5.4% less to 2.6% more on any of the backends:
g.V().hasLabel('person').order().by('name').limit(10), as no index restricted topersonholdsname;has('tag', 'rare')andhas('tag', 'none')beforeorder().by('name').limit(10)of the vertices andorder().by('weight').limit(10)of the edges;order().by('name').by('tag'); orders by the keys of two indexes and bydescription; and the traversals which an index answered before,has('kind', 'k7')of a composite index andhas('name', gt(…))ofmixed. An order by keys which no mixed index holds,taganduid, which reads every vertex with either jar, moved by −9.6% to +8.1% between runs. At 4 threads, the first seven traversals of the table took 99% to 100% less time on every backend; the deep range 89% less on Lucene, 67% less on Elasticsearch and 71% less on Solr; the whole order 84% less on Lucene, 54% less on Solr and 5.7% more on Elasticsearch; and the others moved by −3.3% to +4.6%, but for the order bytaganduid, by up to 8.1%.The whole order is the one which takes longer, and only on Elasticsearch, which returns a result without a limit in pages of
index.search.max-result-set-size, 50 by default: some 640 requests here. In a run of that traversal alone, it took 938 and 907 ms in two passes with pages of 50, 261 and 259 ms with pages of 1,000, and 201 and 201 ms with pages of 10,000, where master's scan took 615 and 606 ms. The scans here read an inmemory backend; one of a storage backend over a network costs more for each vertex, which the traversals that read only the first elements of the index don't pay.Solr read a result larger than a page at growing offsets, in pages of
max-result-set-size, so that the work of an order without a limit, or with a limit beyond a page, grew with the square of its elements: with master'sjanusgraph-solr, this change took 2,944 ms forrange(20000, 20010)and 5,920 ms for the whole order, where master's scan took 607 and 622 ms. Read Solr results larger than a page in growing pages #5127 reads such a result in pages which grow up toindex.search.solr.max-page-size; with it on both sides, this change took 193 and 299 ms, as the table shows. So Read Solr results larger than a page in growing pages #5127 should be merged before this change.An earlier version of this change took the second choice also where JanusGraph checks some of the conditions in memory, as it does for a
has(key)next to them: it reads the index in growing batches and checks each element it returns. Measured in the same way against master3148803d4, it answeredg.V().hasLabel('person').order().by('name').limit(10)with the index of every vertex in about 1.1 ms rather than 571 to 582 ms on Lucene and Elasticsearch, and took 60% less time on Lucene and 26% less on Elasticsearch forhas('tag', 'rare')before the order of the vertices, and 33% less on Lucene forhas('tag', 'none'). But it took 92% longer forhas('tag', 'none')on Elasticsearch, where the batches beyond 10,000 hits come in pages, and longer for the edges, each of which an index hit looks up with a query of its own where a scan reads a vertex's edges at once: forhas('tag', 'none'), 78% longer on Lucene and 345% longer on Elasticsearch, and forhas('tag', 'rare'), 74% longer on Elasticsearch;order().by('name').by('tag'), which the index can't sort, took 11% longer on Elasticsearch. So this change takes the second choice only where the index answers every condition, and leaves the others as they were.Visibility: these traversals now see what a
has(key)sees, as the changelog says, where the scan read what the storage backend holds. An element committed moments before may be missing until the index shows it: Elasticsearch, withbulk-refreshat its default offalse, once it refreshes; Solr, withwait-searcherat its default offalse, once a commit opens a new searcher, which the shippedsolrconfig.xmlleaves tosolr.autoSoftCommit.maxTime(its hard commits every 15 seconds don't open one). The other way round, an element whose order key was removed moments before may still come back, and one whose value changed may come in the order of its old value:QueryProcessorchecks the results of a fitted query against its conditions in memory only for the transaction's own changes (getFilterIterator(…, hasDeletions, !subquery.isFitted())). A vertex removed moments before may come back too, as for ahas(key): the index's ids become vertices bygetInternalVertex, which by default doesn't read the vertex to check that it exists. A Java check bears both out: where a Lucene index still held a vertex which another graph instance on the same BerkeleyJE storage had removed, and the old name of a vertex which it had renamed fromcto0,g.V().order().by('name')returned the removed vertex, without auidor aname, first, and the renamed one last, asg.V().has('name').order().by('name')does on master; master's full scan returned the renamed vertex first and not the removed one. So may an element whose index write or delete failed.A key in two mixed indexes, as
STRINGin one and asTEXTin the other, neither restricted to a label: the candidates leave out theTEXTone, sog.V().order().by('name')reads theSTRINGone every time, where a check of the strategy's choice afterwards would read every element now and then, as Candidates above explains. Two indexes which both hold the key in a way which the backends sort by, asSTRINGandTEXTSTRING, are still taken by chance; each returns the same elements in the same order, but for the order of ties.The filter takes each backend's answer, through
IndexSelectionUtil.indexCoversOrderand Sort in memory the orders by keys which the index backend can't sort #5121'sIndexSerializer.supportsOrdering: an order by aUUIDreads the index on Elasticsearch and Solr, which sort UUIDs by their string forms, as JanusGraph orders them, and one by aSTRINGkey with astring-analyzerreads it on Lucene and Solr, which sort such a key by its whole strings. It adds only a rule for custom parameters, whichsupportsOrderingdoesn't look at: an index which holds an order key with custom parameters is left out on every backend, though only Elasticsearch takes them into its mapping. Such an order reads every element, as before, which costs nothing against master.Index providers of other projects which keep
IndexProvider.supportsOrdering's default of true are taken to sort by every key: such an order now reads their index, also by a key which they can't sort by, as one ofTEXTmapping, where it read every element. They should implementsupportsOrdering, as Sort in memory the orders by keys which the index backend can't sort #5121's changelog asks, and the changelog of this change says so too.Elements which tie on the order keys may come in another order than before, the index's, so that a limit may take others of them. So may elements whose
Instantvalues differ by less than a millisecond: Elasticsearch and Lucene keep instants by the millisecond, and Solr takes no finer one, where JanusGraph compares them whole. LeavingInstantkeys out of the second choice would keep the order of such elements exact, at the cost of every order by a timestamp; the changelog says it instead.Unchanged, and a bug of its own: where an index answers a traversal's conditions, Sort in memory the orders by keys which the index backend can't sort #5121 gives it the order only by the keys which its backend sorts by, but still by a key which it holds with custom parameters, and by one whose field isn't
ENABLED, asIndexSelectionUtil.indexCoversOrderchecks neither. Withkindandtagin one Elasticsearch index,tagwithdoc_valuesfalse,g.V().has('kind', 'k').order().by('tag')fails withCould not call index; and withrankadded to an index ofkindand not yet reindexed,g.V().has('kind', 'k').order().by('rank')comes in the order of the index, which lacks therankof every element which it held before. The second choice leaves both out, by its rule for custom parameters and as it covers the presence of a key only in anENABLEDfield.🤖 Generated with Claude Code