Yuxuan Qing created TINKERPOP-3311:
--------------------------------------

             Summary: A constant-false child filter still expands every neighbor
                 Key: TINKERPOP-3311
                 URL: https://issues.apache.org/jira/browse/TINKERPOP-3311
             Project: TinkerPop
          Issue Type: Bug
          Components: process, tinkergraph
    Affects Versions: 3.8.2, 3.5.1
            Reporter: Yuxuan Qing


# A constant-false child filter still expands every neighbor

## Describe the situation

Hi, Apache TinkerPop developers,

Please consider these two queries:

```groovy
// q1
g.V(root.id()).out('HIGH').filter(
    __.constant(2).is(P.lt(1))
).constant(1)

// q2
g.V(root.id()).out('LOW').filter(
    __.constant(2).is(P.lt(1))
).constant(1)
```

Each query expands one edge label and then applies the same constant 
comparison, `2 < 1`. That comparison always rejects the input. Both queries 
return no rows.

## Which Apache TinkerPop versions are affected?

I reproduced this with TinkerGraph 3.8.2 (OpenJDK 11.0.32.1) and TinkerGraph 
3.5.1 (OpenJDK 11.0.30), using Gremlin-Groovy and the default traversal 
strategies. The TinkerGraph measurements below ran in a fresh in-memory graph 
in a Gremlin Server JVM in Docker on macOS ARM64.

I also ran the same query pair with 300,000 HIGH neighbors and one LOW neighbor 
on JanusGraph 1.2.0 (TinkerPop 3.8.2, BerkeleyJE) and HugeGraph 1.7.0 
(TinkerPop 3.5.1, RocksDB). The median JVM runtimes for q1 and q2 were 
**363.223 ms / 0.357 ms** on JanusGraph and **252.663 ms / 0.148 ms** on 
HugeGraph. Both providers emitted 300,000 and one neighbors into the 
constant-false filter in q1 and q2, respectively.

## How to reproduce

Run this setup, then run q1 and q2 with the same traversal source. Consume the 
results using `toList()`.

```groovy
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph

def tg = TinkerGraph.open()
def g = tg.traversal()
def root = g.addV('Root').property('anchor', 1).next()
300000.times {
    root.addEdge('HIGH', g.addV('Leaf').property('mark', true).next())
}
root.addEdge('LOW', g.addV('Leaf').property('mark', true).next())
```

The root has 300,000 neighbors under `HIGH` and one neighbor under `LOW`.

For q1, I get no rows. Median runtime on 3.8.2 is **125.833 ms**. On 3.5.1 it 
is **120.922 ms**.

For q2, I get no rows. Median runtime on 3.8.2 is **0.094 ms**. On 3.5.1 it is 
**0.090 ms**.

TinkerGraph 3.8.2 `PROFILE` excerpt. Rows with blank counts are shown as 
recorded.

```text
Step                                                               Count  
Traversers       Time (ms)    % Dur
q1
VertexStep(OUT,[HIGH],vertex)                                     300000      
300000          26.867    10.95
TraversalFilterStep([ConstantStep(2), IsStep(lt...                              
             218.394    89.02

q2
VertexStep(OUT,[LOW],vertex)                                           1        
   1           0.010    13.24
TraversalFilterStep([ConstantStep(2), IsStep(lt...                              
               0.013    16.76
```

The final plans retain the constant comparison after the vertex expansion. The 
expansion supplies 300,000 inputs to the filter in q1 and one in q2.

### Expected performance

Please fold a pure constant-false child filter so the traversal can skip the 
preceding read-only expansion.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to