hugegraph+cassadra底层存储实现



阅读次数

参考文档:

1.hugegraph的索引:
https://blog.csdn.net/it1993/article/details/89492296

2.底层存储结构
https://www.jianshu.com/p/c5b1d59b1fcb

###cassadra中的底层存储表

(其中gx开头的基本是给业务数据用的表,而s开头的基本是系统用的表.16张是索引相关的表,3张系统异步任务表,1张counter表,7张存储表)

cqlsh> desc schgraph(测试用的keyspace,根据自己情况修改)
CREATE TABLE schgraph.pk (    //属性定义表
    id int PRIMARY KEY,
    aggregate_type tinyint,
    cardinality tinyint,   //表示该属性是单个值,还是集合?
    data_type tinyint,
    name text,
    properties set<int>,
    status tinyint,
    user_data map<text, text>
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';
CREATE INDEX pk_name_index ON schgraph.pk (name);

CREATE TABLE schgraph.vl (    //顶点定义表 
    id int PRIMARY KEY,
    enable_label_index boolean,
    id_strategy tinyint,
    index_labels set<int>,    //关联到index_label这张表
    name text,
    nullable_keys set<int>,
    primary_keys list<int>,   
    properties set<int>,    //关联到属性表
    status tinyint,
    user_data map<text, text>
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';
CREATE INDEX vl_name_index ON schgraph.vl (name);




CREATE TABLE schgraph.il (   //index_label表,存储索引定义
    id int PRIMARY KEY,
    base_type tinyint,
    base_value int,
    fields list<int>,
    index_type tinyint,
    name text,
    status tinyint
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';
CREATE INDEX il_name_index ON schgraph.il (name);




CREATE TABLE schgraph.el (    //edge_label表,存储边的定义
    id int PRIMARY KEY,
    enable_label_index boolean,
    frequency tinyint,
    index_labels set<int>,
    name text,
    nullable_keys set<int>,
    properties set<int>,
    sort_keys list<int>,
    source_label int,
    status tinyint,
    target_label int,
    user_data map<text, text>
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';
CREATE INDEX el_name_index ON schgraph.el (name);


 CREATE TABLE schgraph.g_v (  //graph_vertices顶点的具体存储
    id blob PRIMARY KEY,
    label int,
    properties map<int, blob>
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';
CREATE INDEX g_v_label_index ON schgraph.g_v (label);


CREATE TABLE schgraph.g_ie (   //边的具体存储
    owner_vertex blob,
    direction tinyint,
    label int,
    sort_values text,
    other_vertex blob,
    properties map<int, blob>,
    PRIMARY KEY (owner_vertex, direction, label, sort_values, other_vertex)
) WITH CLUSTERING ORDER BY (direction ASC, label ASC, sort_values ASC, other_vertex ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';        

CREATE TABLE schgraph.g_oe (  //边的具体存储
    owner_vertex blob,
    direction tinyint,
    label int,
    sort_values text,
    other_vertex blob,
    properties map<int, blob>,
    PRIMARY KEY (owner_vertex, direction, label, sort_values, other_vertex)
) WITH CLUSTERING ORDER BY (direction ASC, label ASC, sort_values ASC, other_vertex ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';
CREATE INDEX g_oe_label_index ON schgraph.g_oe (label);



CREATE TABLE schgraph.s_v ( //整个系统的任务task执行情况,系统中存在很多异步任务,比如新增节点,修改节点都会触发rebuild index这类任务
    id blob PRIMARY KEY,
    label int,
    properties map<int, blob>
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';
CREATE INDEX s_v_label_index ON schgraph.s_v (label);

CREATE KEYSPACE schgraph WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '3'}  AND durable_writes = true;



CREATE TABLE schgraph.s_ie (   //system task
    owner_vertex blob,
    direction tinyint,
    label int,
    sort_values text,
    other_vertex blob,
    properties map<int, blob>,
    PRIMARY KEY (owner_vertex, direction, label, sort_values, other_vertex)
) WITH CLUSTERING ORDER BY (direction ASC, label ASC, sort_values ASC, other_vertex ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';





CREATE TABLE schgraph.s_oe (
    owner_vertex blob,
    direction tinyint,
    label int,
    sort_values text,
    other_vertex blob,
    properties map<int, blob>,
    PRIMARY KEY (owner_vertex, direction, label, sort_values, other_vertex)
) WITH CLUSTERING ORDER BY (direction ASC, label ASC, sort_values ASC, other_vertex ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';
CREATE INDEX s_oe_label_index ON schgraph.s_oe (label);





CREATE TABLE schgraph.c (   //counter表
    schema_type text PRIMARY KEY,
    id counter
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';





CREATE TABLE schgraph.s_ii (
    index_label_id int,
    field_values int,
    element_ids blob,
    PRIMARY KEY (index_label_id, field_values, element_ids)
) WITH CLUSTERING ORDER BY (field_values ASC, element_ids ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';

CREATE TABLE schgraph.g_di (  //属性值为double,对应的索引表?
    index_label_id int,
    field_values double,
    element_ids blob,
    PRIMARY KEY (index_label_id, field_values, element_ids)
) WITH CLUSTERING ORDER BY (field_values ASC, element_ids ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';

CREATE TABLE schgraph.g_fi (  //属性值为float对应的索引表?
    index_label_id int,
    field_values float,
    element_ids blob,
    PRIMARY KEY (index_label_id, field_values, element_ids)
) WITH CLUSTERING ORDER BY (field_values ASC, element_ids ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';



CREATE TABLE schgraph.g_hi (  //属性为text对应的索引表??
    index_label_id int,
    field_values text,
    element_ids blob,
    PRIMARY KEY (index_label_id, field_values, element_ids)
) WITH CLUSTERING ORDER BY (field_values ASC, element_ids ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';

CREATE TABLE schgraph.s_ai (
    field_values text,
    index_label_id int,
    element_ids blob,
    PRIMARY KEY (field_values, index_label_id, element_ids)
) WITH CLUSTERING ORDER BY (index_label_id ASC, element_ids ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';



CREATE TABLE schgraph.s_hi (
    index_label_id int,
    field_values text,
    element_ids blob,
    PRIMARY KEY (index_label_id, field_values, element_ids)
) WITH CLUSTERING ORDER BY (field_values ASC, element_ids ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';



CREATE TABLE schgraph.s_si (
    field_values text,
    index_label_id int,
    element_ids blob,
    PRIMARY KEY (field_values, index_label_id, element_ids)
) WITH CLUSTERING ORDER BY (index_label_id ASC, element_ids ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';

CREATE TABLE schgraph.s_di (
    index_label_id int,
    field_values double,
    element_ids blob,
    PRIMARY KEY (index_label_id, field_values, element_ids)
) WITH CLUSTERING ORDER BY (field_values ASC, element_ids ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';

CREATE TABLE schgraph.s_li (
    index_label_id int,
    field_values bigint,
    element_ids blob,
    PRIMARY KEY (index_label_id, field_values, element_ids)
) WITH CLUSTERING ORDER BY (field_values ASC, element_ids ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';

CREATE TABLE schgraph.s_ui (
    field_values text,
    index_label_id int,
    element_ids blob,
    PRIMARY KEY (field_values, index_label_id, element_ids)
) WITH CLUSTERING ORDER BY (index_label_id ASC, element_ids ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';

CREATE TABLE schgraph.g_li (  //属性值为long对应的索引表?
    index_label_id int,  //对应index_label里面的索引id
    field_values bigint,
    element_ids blob,
    PRIMARY KEY (index_label_id, field_values, element_ids)
) WITH CLUSTERING ORDER BY (field_values ASC, element_ids ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';



CREATE TABLE schgraph.g_ii (  //属性值为int对应的索引表?
    index_label_id int,
    field_values int,
    element_ids blob,
    PRIMARY KEY (index_label_id, field_values, element_ids)
) WITH CLUSTERING ORDER BY (field_values ASC, element_ids ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';

CREATE TABLE schgraph.g_ai (  //和g_hi的区别在哪里?
    field_values text,
    index_label_id int,
    element_ids blob,
    PRIMARY KEY (field_values, index_label_id, element_ids)
) WITH CLUSTERING ORDER BY (index_label_id ASC, element_ids ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';

CREATE TABLE schgraph.s_fi (
    index_label_id int,
    field_values float,
    element_ids blob,
    PRIMARY KEY (index_label_id, field_values, element_ids)
) WITH CLUSTERING ORDER BY (field_values ASC, element_ids ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';


    CREATE TABLE schgraph.g_si (  //🎧s
    field_values text,
    index_label_id int,
    element_ids blob,
    PRIMARY KEY (field_values, index_label_id, element_ids)
) WITH CLUSTERING ORDER BY (index_label_id ASC, element_ids ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';



    CREATE TABLE schgraph.g_ui (
    field_values text,
    index_label_id int,
    element_ids blob,
    PRIMARY KEY (field_values, index_label_id, element_ids)
) WITH CLUSTERING ORDER BY (index_label_id ASC, element_ids ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';

###详细示例

####1.图定义

graph.schema().propertyKey("uid").asText().ifNotExist().create();
graph.schema().propertyKey("shorturl").asText().ifNotExist().create();
graph.schema().propertyKey("timestamp").asLong().ifNotExist().create();
graph.schema().vertexLabel("person").properties("uid").primaryKeys("uid").ifNotExist().create();
graph.schema().vertexLabel("shorturl").properties("shorturl").primaryKeys("shorturl").ifNotExist().create();
graph.schema().indexLabel("createByTime").onE("create").by("timestamp").range().ifNotExist().create();



cqlsh:hgraphtest> select * from pk;                 

 id  | aggregate_type | cardinality | data_type | name               | properties | status | user_data
-----+----------------+-------------+-----------+--------------------+------------+--------+----------------------
   1 |              0 |           1 |         8 |                uid |       null |      1 |                 null
    2 |              0 |           1 |         8 |           shorturl |       null |      1 |                 null
    3 |              0 |           1 |         5 |          timestamp |       null |      1 |                 null



    cqlsh:hgraphtest> select * from vl;  

 id  | enable_label_index | id_strategy | index_labels | name     | nullable_keys             | primary_keys | properties                                                   | status | user_data
-----+--------------------+-------------+--------------+----------+---------------------------+--------------+--------------------------------------------------------------+--------+-----------
   1 |               True |           2 |         null |   person |                      null |          [1] |                                                          {1} |      1 |      null
   2 |               True |           2 |         null | shorturl |                      null |          [2] |                                                          {2} |      1 |      null  

cqlsh:hgraphtest> select * from il;

 id  | base_type | base_value | fields | index_type | name                        | status
-----+-----------+------------+--------+------------+-----------------------------+--------
   1 |         2 |          1 |    [3] |         23 |                createByTime |      2



    cqlsh:hgraphtest> select * from el;

 id | enable_label_index | frequency | index_labels | name   | nullable_keys | properties | sort_keys | source_label | status | target_label | user_data
----+--------------------+-----------+--------------+--------+---------------+------------+-----------+--------------+--------+--------------+-----------
  1 |               True |         1 |          {1} | create |          null |        {3} |      null |            1 |      1 |            2 |      null

(1 rows)

因为我们没有插入顶点和边,这时候g_v,g_ie,g_oe都为空,统计表如图:

cqlsh:hgraphtest> select * from c;

 schema_type  | id
--------------+----
 PROPERTY_KEY |  3
 VERTEX_LABEL |  2
   SYS_SCHEMA | 47
  INDEX_LABEL |  1
   EDGE_LABEL |  1
         TASK |  1

####2.插入顶点

marko = graph.addVertex(T.label, “person”, “uid”,”2229095301”)
url=graph.addVertex(T.label, “shorturl”, “shorturl”,”MfDALoIBLMXbuQIezN6T2Q”)

cqlsh:hgraphtest> select * from g_v;

id | label | properties
——————————————————+——-+——————————————————-
0x8b313a32323239303935333031 | 1 | {1: 0x0a32323239303935333031}
0x97323a4d6644414c6f49424c4d5862755149657a4e36543251 | 2 | {2: 0x164d6644414c6f49424c4d5862755149657a4e36543251}

####3.插入边

marko.addEdge(“create”, url, “timestamp”, 1587779170)

cqlsh:hgraphtest> select * from g_oe;

 owner_vertex                 | direction | label | sort_values | other_vertex                                         | properties
------------------------------+-----------+-------+-------------+------------------------------------------------------+-------------------
 0x8b313a32323239303935333031 |      -126 |     1 |             | 0x97323a4d6644414c6f49424c4d5862755149657a4e36543251 | {3: 0x85f58eac62}

(1 rows)
cqlsh:hgraphtest> select * from g_ie;

 owner_vertex                                         | direction | label | sort_values | other_vertex                 | properties
------------------------------------------------------+-----------+-------+-------------+------------------------------+-------------------
 0x97323a4d6644414c6f49424c4d5862755149657a4e36543251 |      -116 |     1 |             | 0x8b313a32323239303935333031 | {3: 0x85f58eac62}

(1 rows)


cqlsh:hgraphtest> select * from g_li;(timestamp对应的那个range索引)

 index_label_id | field_values | element_ids
----------------+--------------+------------------------------------------------------------------------------------------
              1 |   1587779170 | 0x7e8b313a32323239303935333031820801ff97323a4d6644414c6f49424c4d5862755149657a4e36543251