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: Unexpected behaviour when deleting from a pre-computed table view #3546

Open
2 tasks done
AlexFrid opened this issue Feb 19, 2024 · 0 comments
Open
2 tasks done
Labels
bug Something isn't working topic:surrealql This is related to the SurrealQL query language

Comments

@AlexFrid
Copy link

Describe the bug

The record still partially exists after it has been deleted from a pre-computed table view

    {
        "category": "blue",
        "count": 0,
        "id": "categories:['blue']",
        "max": 4,
        "sum": 0
    }

Issue created based on this StackOverflow question:
https://stackoverflow.com/questions/77923527/difference-of-pre-computed-tables-in-surrealdb-and-sql-views-when-deleting-an-el

Steps to reproduce

  1. Define a simple item table with category and amount field:
DEFINE TABLE item SCHEMAFULL;
DEFINE FIELD category ON TABLE item TYPE string;
DEFINE FIELD amount ON TABLE item TYPE number;
  1. Created a pre-computed table categories with a GROUP BY-clause and some window functions.
DEFINE TABLE categories AS 
   SELECT category, 
          math::sum(amount) AS sum, 
          count() as count, 
          math::max(amount) as max
   FROM item 
   GROUP BY category;
  1. Add two items of category "green" and one (item:C) of category "blue".
CREATE item:A SET category="green", amount=2;
CREATE item:B SET category="green", amount=3;
CREATE item:C SET category="blue", amount=4;
  1. deleteitem:C. Thus, no items of category "blue" are left.
DELETE item:C;
  1. A simple select of TABLE item shows the removal of item:C (and of the category "blue"):
SELECT * FROM item;
[
    {
        "amount": 2,
        "category": "green",
        "id": "item:A"
    },
    {
        "amount": 3,
        "category": "green",
        "id": "item:B"
    }
]
  1. But when doing a SELECT on pre-computed TABLE categories, the category "blue" still exists (contrary to my expectation). It has - as expected - no rows (count) and a sum of 0. But - again contrary to my expectations - the "blue" category has a max-value:
SELECT * FROM categories;

    {
        "category": "blue",
        "count": 0,
        "id": "categories:['blue']",
        "max": 4,
        "sum": 0
    },
    {
        "category": "green",
        "count": 2,
        "id": "categories:['green']",
        "max": 3,
        "sum": 5
    }
]

Expected behaviour

Expected behaviour can be reproduced by the SELECT statement itself, which serves as the base for the definition of the pre-computed table:

SELECT category, 
          math::sum(amount) AS sum, 
          count() as count, 
          math::max(amount) as max
   FROM item 
   GROUP BY category;
[
    {
        "category": "green",
        "count": 2,
        "max": 3,
        "sum": 5
    }
]

SurrealDB version

1.2.1 for macos on aarch64

Contact Details

alexander.fridriksson@surrealdb.com

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@AlexFrid AlexFrid added bug Something isn't working topic:surrealql This is related to the SurrealQL query language labels Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working topic:surrealql This is related to the SurrealQL query language
Projects
None yet
Development

No branches or pull requests

1 participant