seq_name列在ag_label表中是什么?

huangapple go评论96阅读模式
英文:

What is the seq_name column in the ag_label table?

问题

"seq_name" 列是什么意思?

英文:

I'm working on a new feature that involves labels for Apache AGE and I'm looking for tools with which I can work with.

In psql interface, when you input the command SELECT * FROM ag_catalog.ag_label; the following output is shown:

       name       | graph  | id | kind |       relation        |       seq_name
------------------+--------+----+------+-----------------------+-------------------------
 _ag_label_vertex | 495486 |  1 | v    | test._ag_label_vertex | _ag_label_vertex_id_seq
 _ag_label_edge   | 495486 |  2 | e    | test._ag_label_edge   | _ag_label_edge_id_seq
 vtx_label        | 495486 |  3 | v    | test.vtx_label        | vtx_label_id_seq
 elabel           | 495486 |  4 | e    | test.elabel           | elabel_id_seq

I came across this and wasn't able to figure out what kind of data I can retrieve from it, what is it used for or how can it help me.

Can you explain the seq_name column?

答案1

得分: 1

Seq_name 指的是序列。序列是可以被视为“数字生成器”的单行表,它们从某个最小整数值开始,然后随着它们被“消耗”而递增。

与列相关联的序列可用于为其分配值。例如,与表“mytable”中的列“id”关联的“mytable_seq_id”可以从1开始。然后,当您向mytable添加更多条目时,“id”列开始递增为2、3等等。

关于创建序列的Postgres文档:

https://www.postgresql.org/docs/current/sql-createsequence.html

至于AGE,这里有一段摘自“graph_commands.c”源文件的注释。它描述了如何使用序列生成标签ID。

static Oid create_schema_for_graph(const Name graph_name)
{
    char *graph_name_str = NameStr(*graph_name);
    CreateSchemaStmt *schema_stmt;
    CreateSeqStmt *seq_stmt;
    TypeName *integer;
    DefElem *data_type;
    DefElem *maxvalue;
    DefElem *cycle;
    Oid nsp_id;

    /*
     * 这与运行以下SQL语句相同。
     *
     * CREATE SCHEMA `graph_name`
     *   CREATE SEQUENCE `LABEL_ID_SEQ_NAME`
     *     AS integer
     *     MAXVALUE `LABEL_ID_MAX`
     *     CYCLE
     *
     * 该序列将用于为图中的标签分配唯一的ID。
     *
     * schemaname不一定非得是graph_name,但使用相同的名称使用户可以仅通过名称找到图的后端模式。
     *
     * 此命令的ProcessUtilityContext是PROCESS_UTILITY_SUBCOMMAND,因此不会触发事件触发器。
     */
}

请注意,序列也在AGE内部的其他函数中使用,上述函数只是一个示例。

英文:

Seq_name refers to sequences. Sequences are single-row tables that can be thought of as 'number generators' that start at some minimum integer value and then increment as they are 'consumed'.

A sequence that is associated with a column can be used to assign values to it. For example, 'mytable_seq_id' associated with column 'id' in a particular table 'mytable' might start at 1. Then as you add more entries to mytable, the 'id' column begins to increment to 2,3 and so on.

Postgres docs on creating sequences:

https://www.postgresql.org/docs/current/sql-createsequence.html

As for AGE, here's a comment taken directly out of the 'graph_commands.c' source file. It describes how sequences are used to generate labels ids.

static Oid create_schema_for_graph(const Name graph_name)
{
    char *graph_name_str = NameStr(*graph_name);
    CreateSchemaStmt *schema_stmt;
    CreateSeqStmt *seq_stmt;
    TypeName *integer;
    DefElem *data_type;
    DefElem *maxvalue;
    DefElem *cycle;
    Oid nsp_id;

    /*
     * This is the same with running the following SQL statement.
     *
     * CREATE SCHEMA `graph_name`
     *   CREATE SEQUENCE `LABEL_ID_SEQ_NAME`
     *     AS integer
     *     MAXVALUE `LABEL_ID_MAX`
     *     CYCLE
     *
     * The sequence will be used to assign a unique id to a label in the graph.
     *
     * schemaname doesn't have to be graph_name but the same name is used so
     * that users can find the backed schema for a graph only by its name.
     *
     * ProcessUtilityContext of this command is PROCESS_UTILITY_SUBCOMMAND
     * so the event trigger will not be fired.
     */

Note that sequences are used in other functions in the AGE internals as well, and the above function is just one example.

答案2

得分: 0

The "ag_label" 表是AgensGraph扩展程序用于PostgreSQL的系统目录表。该表用于存储有关图中标签的信息,这些标签类似于传统图中的节点。

"ag_label" 表中的 'seq_name' 列用于存储与标签关联的序列的名称。序列用于唯一标识符。

当我们向图中插入节点时,会查询 "ag_label" 表以查找节点的标签的适当序列。

英文:

The "ag_label" table is a system catalog table that is used by the AgensGraph extension for PostgreSQL.
This table is used to store information about Labels in the grapg which are similar to nodes in a traditional graph.

The 'seq_name' col in the "ag_label" table is used to store name of sequence that is being associated with label. Sequences are used for unique idenfiers.

When we inset node in to graph the "ag_label" table is consulted to find appropriate sequence for label of node.

huangapple
  • 本文由 发表于 2023年2月13日 23:03:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75437624.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定