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

Add ALTER TABLE ... RENAME TO ... #95

Closed
yaziine opened this issue Jun 12, 2020 · 1 comment · Fixed by #114
Closed

Add ALTER TABLE ... RENAME TO ... #95

yaziine opened this issue Jun 12, 2020 · 1 comment · Fixed by #114
Assignees
Labels
enhancement New feature or request sql SQL API and syntax
Milestone

Comments

@yaziine
Copy link
Collaborator

yaziine commented Jun 12, 2020

This is a sub-issue of #94 that focuses on renaming an existing table.

We should be able to do the following:

genji> CREATE TABLE foo;
genji> INSERT INTO foo VALUES {name: "John Doe"};
genji> ALTER TABLE foo RENAME TO bar;
genji> SELECT * FROM bar;
{
  "name": "John Doe"
}
genji> SELECT * FROM foo;
table not found

If the table bar already exists, we should return an error.

@yaziine yaziine added enhancement New feature or request sql SQL API and syntax labels Jun 12, 2020
@yaziine yaziine added this to the v0.6.0 milestone Jun 12, 2020
@yaziine yaziine self-assigned this Jun 12, 2020
@asdine asdine modified the milestones: v0.6.0, v0.7.0 Jun 28, 2020
@yaziine
Copy link
Collaborator Author

yaziine commented Jul 1, 2020

After reflexion I think that we need to change how the db is structured to handle the renaming of a table.

Currently, how the DB is structured forces us to duplicate all documents of a given table if we want to rename it.
Time complexity: O(n) and Space complexity O(n) as well.

What I suggest is to break the actual DB schema to save some complexity if we want to rename a table.

_genji.tables:
          foo: {store: 123abc, config: 456def},
          bar: {store: 111aaa, config: 789ghi}
123abc: <table's content>
111aaa: <table's content>

That way we can rename a table in a constant time (O(1)) because we only need to change the name of the table in _genji.tables store.
The store allows us to have a reference to the content of the table. We can use an uuid for generating the store value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request sql SQL API and syntax
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants