Primary Id As Attribute

What are the advantages and disadvantages of creating a Primary Id as an attribute?

Thank you.

1 Like

If the primary id is set as an attribute, then it is stored as an ordinary attribute in the database, so you can look at its value in a query, for example in a WHERE clause.

If this is not done, then you will get errors when trying to access the value because it isn’t stored in the database.

This can be surprising as it is completely different to what one expects coming from the relational world. Nevertheless, particularly if the primary key is a GUID or similar, you really don’t care about the id, so it doesn’t need to be stored both in the GSE dictionary (which maps primary keys to the physical locations of the records) and the database records themselves.

It is built that way because we often store really enormous graphs, and being memory resident, those few bytes can make a big difference to space requirements and therefore cost. It also can speed up calculation as we can fit more data into the cpu cache.

Personally, I almost always tick that box for convenience unless I know the key is synthetic, and therefore not meaningful, and I will not be manually composing a result-set that needs the key.

Note, the real primary key is automatically returned in vertex-set based result sets in either case (we recover the key from the dictionary in that case).

2 Likes

Thank you for the explanation, this was very helpful.

can we enable the option after creating the graph or vertex @Richard_Henderson

no. You need to do schema change and reload. Defining a Graph Schema :: GSQL Language Reference