vaticle / typedb

TypeDB: the polymorphic database powered by types
https://typedb.com
Mozilla Public License 2.0
3.72k stars 338 forks source link

Duplicate insertions #6970

Closed maydanw closed 5 months ago

maydanw commented 5 months ago

Description

When inserting data I see duplicated insertions

Environment

  1. TypeDB distribution: Core
  2. TypeDB version: 2.63
  3. Environment: Windows
  4. Client and version: TypeDB Studio
  5. Other details:

Reproducible Steps

  1. Set up files.zip

  2. Extract the zip file

  3. In TypeDB Studio create a new database and set to schema writing state

  4. Run Files 01, 03, 04, 05

  5. Set to writing data state and add 02, 06, 07

  6. Watch closely at 07 and specifically at adding the RAM

  7. Execute

    match
    $ram isa part, has name "RAM";
    $supplier1 isa supplier, has name "ElectroParts Ltd.";
    $purchase1_ram (provider: $supplier1, provided_part: $ram) isa purchased;
    get $purchase1_ram;
  8. Unexpected result You will notice there are two different purchases of RAM even yet only one was inserted

Expected result

Single purchase

Additional information

Relevant logs from TypeDB or Driver:

izmalk commented 5 months ago

After following the steps above, I've got the results below:

Screenshot 2024-01-16 at 11 21 44 Screenshot 2024-01-16 at 11 21 08

I believe these results confirm the theory, that the match clause in the insert query in the file 07 matches two results; hence the insert clause is executed twice, inserting two relations: $purchase1_ram (provider: $supplier1, provided_part: $ram) isa purchased, has purchase_date 2024-01-11, has quantity 400, has price 30000.00;. That explains the duplication of the relation. That behavior is expected and documented: https://development.typedb.com/docs/typeql/data/insert#_matching_in_an_insert_query

maydanw commented 5 months ago

This was the problem I had. From my understanding, the reason was that 2 of the parts in the MATCH parts had the same name but different serial numbers. This causes the whole block to run twice and enter the purchase relation twice even due it was defined only once. There is still something confusing there as I defined the insertion once and there is only one RAM entity but for the specific case at hand, I changed it to work with the serial numbers, and the issue was solved.

[image: Mailtrack] https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality11& Sender notified by Mailtrack https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality11& 16.01.24, 15:20:59

On Tue, 16 Jan 2024 at 13:35, Vladimir Izmalkov @.***> wrote:

After following the step above, I've got the results below:

Screenshot.2024-01-16.at.11.21.44.png (view on web) https://github.com/vaticle/typedb/assets/48120135/f7560dd5-f47c-4a2e-919b-e9d0659f44cd Screenshot.2024-01-16.at.11.21.08.png (view on web) https://github.com/vaticle/typedb/assets/48120135/add91058-0cb2-48a6-aa13-d88f98075215

I believe those results confirm the theory, that the match clause in the insert query in the file 07 matches two results, hence the insert clause is executed twice, inserting two relations: $purchase1_ram (provider: $supplier1, provided_part: $ram) isa purchased, has purchase_date 2024-01-11, has quantity 400, has price 30000.00;. That explains the duplication of the relation. That behavior is expected and documented: https://development.typedb.com/docs/typeql/data/insert#_matching_in_an_insert_query

— Reply to this email directly, view it on GitHub https://github.com/vaticle/typedb/issues/6970#issuecomment-1893568092, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIPXPISW6ONPK4WVKSXUVDYOZQZNAVCNFSM6AAAAABB4TBMP2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJTGU3DQMBZGI . You are receiving this because you authored the thread.Message ID: @.***>

flyingsilverfin commented 5 months ago

Closing since it is resolved.