Index in RedisGraph(RedisGraph的索引)

Index in RedisGraph

概述

索引是图数据库设计和开发的重要方面。索引可以大大提升数据库的查询效率。

举个例子,当RedisGraph处理以下请求(query):

GRAPH.QUERY DEMO_GRAPH "MATCH (n:作品)-[]-(m:角色) where m.name='郭靖' return n.name"

如果没有建立相应的索引,那RedisGraph将不得不对label是角色的节点进行遍历,查询效率低下;如果存在相应的索引,RedisGraph可以根据name='郭靖’直接找到目标节点,避免低效的遍历操作。

Overview of index in RedisGraph

RedisGraph中并没有索引的代码实现,其使用RediSearch搜索引擎来构造索引。

RediSearch是一个高性能的全文搜索引擎,可作为一个Redis Module 运行在Redis上。RediSearch的核心数据结构是Inverted index,也就是hashtable。也就是说,RedisGraph中的索引为哈希索引。

RedisGraph中的索引分为两种:

  • exact match index

    RedisGraph仅支持对node/edge建立单属性索引。

    比如,我们可以在label是角色的节点上为name属性建立单属性索引:

    GRAPH.QUERY DEMO_GRAPH "CREATE INDEX ON :Person(age)"
    
  • full-text index

    RedisGraph利用RediSearch的索引功能,通过procedure call提供全文索引。

    比如,我们可以在label为“角色”的所有节点的name属性上构造全文索引:

    GRAPH.QUERY DEMO_GRAPH "CALL db.idx.fulltext.createNodeIndex('Person', 'name')"
    
Implementation of index in RedisGraph

首先,我们来看一下Index的实现。Index存在两种类型,即为exact-match 、 fulltext,其支持对node/edge建立单属性索引。RedisGraph使用RediSearch搜索引擎来构造索引,Index封装了RedisGraph中RSIndex

typedef struct {
	char *label;                  // indexed label
	int label_id;                 // indexed label ID
	IndexField *fields;           // indexed fields
	char *language;               // language
	char **stopwords;             // stopwords
	GraphEntityType entity_type;  // entity type (node/edge) indexed
	IndexType type;               // index type exact-match / fulltext
	RSIndex *idx;                 // rediSearch index
} Index;

RedisGraph使用Schema来组织索引。对于每一种entity (node/edge),RedisGraph均会维护一个SchemaSchema中存储着与该entity (node/edge)相关的所有索引。

typedef struct {
	int id;               // schema id
	char *name;           // schema name
	SchemaType type;      // schema type (node/edge)
	Index *index;         // exact match index
	Index *fulltextIdx;   // full-text index
} Schema;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值