orientechnologies / orientechnologies/orientdb

Queries with embedded queries in where clause fail to use indexes.

Open
#9,897 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
5k
Forks
868
Avg merge
15h 6m
Merged PRs (30d)
18

Description

OrientDB Version: 3.2.10
Java Version: 17.0.1+12-39
OS: RHEL 8.6

Expected behavior

Queries with embedded queries in where clause should use appropriate indexes when executing.

Actual behavior

select from UOM_RELATIONSHIP_TYPE where inCOI = (select @rid from COI where COI_NAME = 'my coi') or
select from UOM_RELATIONSHIP_TYPE where inCOI.COI_NAME = 'my coi'
executes in 300ms because it is doing a full scan of each vertex type

While doing this:

var rid = oDatabaseDocument.query("select @rid from COI where COI_NAME = 'my coi'");
var output = oDatabaseDocument.query("select from UOM_RELATIONSHIP_TYPE where inCOI = " + rid);

executes in 9ms, because it uses indexes and avoids a full scan.

Steps to reproduce

  1. Create 2 tables with one that has an out edge to the other.
  2. Index the search field (from example above a unique btree on COI_NAME)
  3. Populate with some data.
  4. Create a query that uses the out edge as the filter.
  5. Execute the query with the PROFILE key word to see the databases execution plan, it should fail to use indexes.
  6. Execute the query in the console and time the response.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Reproduce the two queries on OrientDB 3.2.10 with PROFILE, compare their execution plans with the variable-based version, and trace the query-planning path responsible for index selection. Done means the embedded-query forms use the appropriate indexes and avoid full scans.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
databases, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.