are indexes leveraged for ' > ' and ' < ' in a where clause?

18 views
Skip to first unread message

Javad Karabi

unread,
Jan 17, 2014, 10:38:23 AM1/17/14
to ne...@googlegroups.com
for example, i executed (once with and without index one :Member(birth_year) ):

MATCH (m:Member)
WHERE m.birth_year > 1980 AND m.birth_year < 2000
RETURN m

and i noticed that the time to perform the query did not change.

this led me to believe that the index did not help.
does this mean that the index does not help when performing > and < in a WHERE clause?

Michael Hunger

unread,
Jan 17, 2014, 10:47:10 AM1/17/14
to ne...@googlegroups.com
No range queries are planned after 2.1

Sent from mobile device
--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Javad Karabi

unread,
Jan 17, 2014, 10:54:50 AM1/17/14
to ne...@googlegroups.com
on a similar note, 

MATCH (p:Product)<-[c:contains]-(w:Warehouse)
WHERE c.available = 1
RETURN p

is it possible to create an index on the contains relationship, and available attribute, such that this query could lookup the index to perform faster?



--
You received this message because you are subscribed to a topic in the Google Groups "Neo4j" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/neo4j/t_9WyTuI4rQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to neo4j+un...@googlegroups.com.

Michael Hunger

unread,
Jan 17, 2014, 11:47:14 AM1/17/14
to ne...@googlegroups.com
Something like that is planned to be adressed in 2.1

Sent from mobile device

Javad Karabi

unread,
Jan 17, 2014, 3:07:39 PM1/17/14
to ne...@googlegroups.com
is it possible to accomplish this using gremlin, or the java api?
that is, if i was to attempt to search for nodes with birth_year > x, via gremlin or java, would the index be used?

Michael Hunger

unread,
Jan 17, 2014, 3:16:20 PM1/17/14
to ne...@googlegroups.com
Indexes are exact lookups.

Except if you did a manual numeric legacy indexes

db.index().forNodes("member_age").add(node,"birth_year",ValueContext.numeric(node.get("birth_year"));

db.index().forNodes("member_age").query(NumericRangeQuery.newIntRange("birth_year", from , to, true, true));



    @Override
    public EndResult<T> findAllByRange(final String indexName, final String property, final Number from, final Number to) {
        return queryResult(indexName, new Query<S>() {
            public IndexHits<S> query(ReadableIndex<S> index) {
                return index.query(property, createInclusiveRangeQuery(property, from, to));
            }
        });
    }

    @SuppressWarnings("unchecked")
    protected <T extends Number> NumericRangeQuery<T> createInclusiveRangeQuery(String property, Number from, Number to) {
        if (from instanceof Long) return (NumericRangeQuery<T>) NumericRangeQuery.newLongRange(property, from.longValue(),to.longValue(),true,true);
        if (from instanceof Integer) return (NumericRangeQuery<T>) NumericRangeQuery.newIntRange(property, from.intValue(), to.intValue(), true, true);
        if (from instanceof Double) return (NumericRangeQuery<T>) NumericRangeQuery.newDoubleRange(property, from.doubleValue(), to.doubleValue(), true, true);
        if (from instanceof Float) return (NumericRangeQuery<T>) NumericRangeQuery.newFloatRange(property, from.floatValue(), to.floatValue(), true, true);
        return (NumericRangeQuery<T>) NumericRangeQuery.newIntRange(property, from.intValue(), to.intValue(), true, true);
    }

Javad Karabi

unread,
Jan 17, 2014, 4:42:16 PM1/17/14
to ne...@googlegroups.com
michael, just wanted to say thank you for taking the time to do that!
Reply all
Reply to author
Forward
0 new messages