-1

I think indexing is important to look for the wanted data in a database. Can someone introduce how indexing works in Nebula Graph?

ivarni
  • 17,658
  • 17
  • 76
  • 92
Amber Zhang
  • 182
  • 1
  • 6

1 Answers1

0

I noticed how the index works in nebula. Assume you have a tag: tag (col1, col2) You can create different indexes on the tag:

  • index1 on tag(col1)
  • index2 on tag(col2)
  • index3 on tag(col1, col2)
  • index4 on tag(col2, col1)

When nebula scans the indexes, there are great difference in the above 4 indexes. Nebula will choose one that best fits your situation. For example:

  • lookuo on tag where tag.col1 ==1 ->> the best index is index1
  • lookup on tag where tag.col2 == 2 ->> the best index is index2
  • lookup on tag where tag.col1 > 1 and tag.col2 == 1 ->> index3 and index4 are equal here. But nebula will choose index4 as the best because tag.col2 == 1 is an equal query, using tag.col2 first is more efficient.

Examples:

CREATE SPACE my_space(partition_num=3, replica_factor=1);
USE my_space;
CREATE TAG lookup_tag_1(col1 string, col2 string, col3 string);
CREATE TAG INDEX t_index_1 ON lookup_tag_1(col1, col2, col3);

DROP

 drop TAG INDEX t_index_1;

LOOKUP

INSERT VERTEX lookup_tag_1(col1, col2, col3) VALUES 200:("col1_200", "col2_200", "col3_200"),  201:("col1_201", "col2_201", "col3_201"), 202:("col1_202", "col2_202", "col3_202");

 LOOKUP ON lookup_tag_1 WHERE lookup_tag_1.col1 == "col1_200";
============
| VertexID |
============
| 200      |
------------

 LOOKUP ON lookup_tag_1 WHERE lookup_tag_1.col1 == "col1_200" YIELD lookup_tag_1.col1, lookup_tag_1.col2, lookup_tag_1.col3;
========================================================================
| VertexID | lookup_tag_1.col1 | lookup_tag_1.col2 | lookup_tag_1.col3 |
========================================================================
| 200      | col1_200          | col2_200          | col3_200          |
------------------------------------------------------------------------
Amber Zhang
  • 182
  • 1
  • 6