1

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?

Marco Souza
  • 296
  • 7

2 Answers2

1

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.

moeed865
  • 304
  • 1
  • 6
0

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343