Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Add primary key with same value not throwing error #2742

Open
1 task done
mkj-git opened this issue Mar 5, 2025 · 3 comments
Open
1 task done

[Bug] Add primary key with same value not throwing error #2742

mkj-git opened this issue Mar 5, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@mkj-git
Copy link

mkj-git commented Mar 5, 2025

Bug Type (问题类型)

None

Before submit

  • 我已经确认现有的 IssuesFAQ 中没有相同 / 重复问题 (I have confirmed and searched that there are no similar problems in the historical issue and documents)

Environment (环境信息)

  • Server Version: Build from source code
  • Backend: Memory
  • OS: Ubuntu
  • Data Size: 2 vertices

Expected & Actual behavior (期望与实际表现)

If primary key is about having a unique value then following test case must throw some exception but its passing. Why its silently rejecting second vertex? It should have some config that let schema decide that in case of duplicate should it be ignored or throw exception.

    @Test
    public void testPrimaryKey() {

        HugeGraph graph = graph();
        SchemaManager schema = graph.schema();

        schema.propertyKey("prop").asInt().create();
        schema.propertyKey("id").asInt().create();

        schema.vertexLabel("user").primaryKeys("prop")
                .properties("id", "prop").create();

        graph.tx().commit();
        graph().addVertex(T.label, "user", "id", 1, "prop", 10);
        graph.tx().commit();
        graph().addVertex(T.label, "user", "id", 1, "prop", 10);
        graph.tx().commit();

        List<Vertex> persons = graph().traversal().V()
                .hasLabel("user").toList();
        Assert.assertEquals(1, persons.size());
    }

Vertex/Edge example (问题点 / 边数据举例)

Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)

@mkj-git mkj-git added the bug Something isn't working label Mar 5, 2025
Copy link

dosubot bot commented Mar 5, 2025

In HugeGraph, when using the memory backend, the default behavior for handling duplicate entries is to merge columns if the entry already exists. This means that if you attempt to insert a vertex with a duplicate primary key, the system will not throw an exception but will instead merge the new entry with the existing one. This is why your test case is passing without an error, and only one vertex is present in the result [1].

Currently, there is no configuration option available to change this default behavior of merging entries in the memory backend [1]. If you require different behavior, such as throwing an exception for duplicate primary keys, you might need to implement custom logic or consider using a different backend that supports such a feature.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@imbajin
Copy link
Member

imbajin commented Mar 6, 2025

In HugeGraph, when using the memory backend, the default behavior for handling duplicate entries is to merge columns if the entry already exists. This means that if you attempt to insert a vertex with a duplicate primary key, the system will not throw an exception but will instead merge the new entry with the existing one. This is why your test case is passing without an error, and only one vertex is present in the result [1].

Currently, there is no configuration option available to change this default behavior of merging entries in the memory backend [1]. If you require different behavior, such as throwing an exception for duplicate primary keys, you might need to implement custom logic or consider using a different backend that supports such a feature.

To continue talking to Dosu, mention @dosu.

Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@mkj-git @dosu (All backends have the same logic, not only the memory)

In HG's design, the primary key mode does not mean that the key cannot be duplicated. The fundamental reason is that in LSM-tree structure, there is only the concept of append without updating, which results in much faster write performance (without the need to read it again)

So by default, the same vid/id will be overwritten instead of reporting an error. If you need a unique constraint, we support a unique index to achieve this effect. If you need to update, we have separate single vertex and batch update interfaces that can meet your needs

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants