Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Add support for DROP VIEW #860

Open
wants to merge 7 commits into
base: feature/views
Choose a base branch
from

Conversation

agarciamontoro
Copy link
Contributor

@agarciamontoro agarciamontoro commented Oct 29, 2019

This PR adds support for DROP VIEW statements, as in

DROP VIEW [IF EXISTS] [db_name1.]view_name1 [, [db_name2.]view_name2, ...] [RESTRICT] [CASCADE]

As each view in the statement may come from a different database, I have decided to model the plan as follows:

  • There is a parent node, DropView, that just contains a list of children of type SingleDropView.
  • The nodes SingleDropView implement the Databaser interface so the analyzer can resolve the database in each of them.

The actual removal of the views happen in the RowIter from DropView, as we need to:

  1. Lock the ViewRegistry mutex.
  2. Check that all views in the children member of DropView can be deleted (i.e., they exist or they do not exist but the user has added the IF EXISTS keyword to the statement)
  3. Delete all of the views listed if the previous step raised no error.
  4. Release the mutex.

I first started implementing the removal in the SingleDropView nodes, but then it was difficult to check that all views could be deleted and then delete them, all in an atomic operation. The final implementation makes this easy with the new DeleteList from ViewRegistry.

Signed-off-by: Alejandro García Montoro <[email protected]>
Signed-off-by: Alejandro García Montoro <[email protected]>
Signed-off-by: Alejandro García Montoro <[email protected]>
Signed-off-by: Alejandro García Montoro <[email protected]>
Signed-off-by: Alejandro García Montoro <[email protected]>
@agarciamontoro agarciamontoro requested a review from a team as a code owner October 29, 2019 11:29
Copy link
Contributor

@erizocosmico erizocosmico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! Just two minor things and LGTM

sql/parse/util.go Outdated Show resolved Hide resolved
sql/plan/drop_view.go Show resolved Hide resolved
Signed-off-by: Alejandro García Montoro <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants