Skip to content

Support foreign keys #9

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Support foreign keys #9

wants to merge 5 commits into from

Conversation

dutow
Copy link
Collaborator

@dutow dutow commented Jun 30, 2025

The goal of this PR is to add foreign keys to stormweaver tests. This is a prerequisite for later PRs/features, which will add complex selects / views / materialized views to the testing.

This PR includes several commits:

  • Support for composite actions (e.g. CREATE and then INSERT) so that we create tables with some data in them by default
  • Fix the primary keys of partitioned tables: the partition key is now also the primary key, it's the first column instead of the second, the only difference from normal primary keys is that it's not auto generated with a sequence
  • Small refactoring: extract the random table selection logic into it's own helper from dml.cpp
  • Improve drop column generation: do not drop primary keys. While this could be a useful test, current code relies on the existence of the primary keys.
  • Add support for foreign keys.

dutow added 5 commits June 30, 2025 07:39
This commit adds two composite actions:
* one tuple like, which executes the specified actions sequentially
* one repeating composite, which executes a single action the specified
  N times

These are used to improve the create table logic, which previously only
created empty tables. Now the named create actions execute two sql
statements, one which creates the table and one which does the insert.

There's no transaction handling for now, as failure is okay:
* if the create table fails, it throws an exception, and the second
  action (insert) is never executed
* if the insert fails, that's okay, we end up with an empty table,
that is the same as before. And most likely if it fails, that's because
something already deleted the table

There's also some related refactoring which allows the code to pass the
table reference from the create command to the insert. This is not the
prettiest code, it might need refactoring later when we firure out
something better.
Before this commit partitioned tables had no primary keys: create table
generated a serial column without a unique constraint, and a partition
key without a unique constrant.

As the partition key has a high range and has very small chance to
generate duplicates, this commit removes the serial column from the
partitioned tables, and makes the first column the primary key and
partition key.

This simplifies things as now all tables have a primary key in the first
column, even if it isn't auto generated.
Also modify its behavior to throw an ActionException when it can't
select a failed table, to improve the statistics. With this change if an
action is skipped because a failed lookup, it will show up in the
failure section of statistics instead of success.
While testing tables without primary keys could be useful, currently
stormweaver relies on its existence at a few places. This change could
be reverted once those parts are improved.
This commit adds foreign keys randomly to the test tables. For now it
makes some assumptions, for example every table can have 0 or 1 foreign
keys, and it's always the second column. The first column is also
renamed simply to "id" for easier lookup in insert/update code.
@dutow dutow requested review from dAdAbird and jeltz as code owners June 30, 2025 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant