Skip to content

Conversation

VinaiRachakonda
Copy link
Contributor

No description provided.

@VinaiRachakonda VinaiRachakonda changed the title [WIP] Vinai/temporary tables Vinai/temporary tables May 31, 2021
Copy link
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

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

Mostly good, but needs some additional cleanup with your additions, this is getting messy.

Also, you need another test: make sure that temp tables don't show up for SHOW TABLES

@@ -620,6 +627,12 @@ type TableCreator interface {
CreateTable(ctx *Context, name string, schema Schema) error
}

type TemporaryTableCreator interface {
Copy link
Member

Choose a reason for hiding this comment

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

Interface doc: "TemporaryTableCreator is a database that can create temporary tables that persist only as long as the session"

Also embed the Database interface

Copy link
Member

Choose a reason for hiding this comment

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

Put it in the wrong place, needs to go above the interface. Also document the fact that temp table with the same name as an existing table are permitted and take precedence, here and in GetTableInsensitive

Also CreateTemporaryTable needs method doc

@@ -540,6 +541,12 @@ type TriggerDatabase interface {
DropTrigger(ctx *Context, name string) error
}

// TemporaryTableDatabase is a database that can query the session (which manages the temporary table state) to
// retrieve the name of all temporary tables.
type TemporaryTableDatabase interface {
Copy link
Member

Choose a reason for hiding this comment

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

Get rid of this, no need for this interface

Just iterate over all tables and ask each one if it's temp or not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved in DMs

sql/plan/ddl.go Outdated
}

var _ sql.Databaser = (*CreateTable)(nil)
var _ sql.Node = (*CreateTable)(nil)
var _ sql.Expressioner = (*CreateTable)(nil)

// NewCreateTable creates a new CreateTable node
func NewCreateTable(db sql.Database, name string, ifNotExists bool, tableSpec *TableSpec) *CreateTable {
func NewCreateTable(db sql.Database, name string, ifNotExists bool, temporary bool, tableSpec *TableSpec) *CreateTable {
Copy link
Member

Choose a reason for hiding this comment

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

Clean this up: use bool alias types instead of bools for these two params, and introduce consts for them

type IfNotExists bool
type TempTable bool

IfNotExists = true
IfNotExistsAbsent = false
IsTempTable = true
IsNotTempTable = false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I experimented with this and feels little messier tbh. I'll push to review though and we can reassess

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nvm

sql/plan/ddl.go Outdated
if c.temporary {
creatable, ok := c.db.(sql.TemporaryTableCreator)
if !ok {
return sql.RowsToRowIter(), fmt.Errorf("error: database does not support temporary tables")
Copy link
Member

Choose a reason for hiding this comment

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

Define an err type for this

sql/plan/ddl.go Outdated

//TODO: in the event that foreign keys or indexes aren't supported, you'll be left with a created table and no foreign keys/indexes
//this also means that if a foreign key or index fails, you'll only have what was declared up to the failure
if len(c.idxDefs) > 0 || len(c.fkDefs) > 0 || len(c.chDefs) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Split this up into three separate parts and extract a method for each

Copy link
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

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

LG, just a few comments

@@ -620,6 +627,12 @@ type TableCreator interface {
CreateTable(ctx *Context, name string, schema Schema) error
}

type TemporaryTableCreator interface {
Copy link
Member

Choose a reason for hiding this comment

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

Put it in the wrong place, needs to go above the interface. Also document the fact that temp table with the same name as an existing table are permitted and take precedence, here and in GetTableInsensitive

Also CreateTemporaryTable needs method doc

sql/plan/ddl.go Outdated
@@ -42,6 +42,24 @@ var ErrNullDefault = errors.NewKind("column declared not null must have a non-nu
// ErrTableCreatedNotFound is thrown when a table is created from CREATE TABLE but cannot be found immediately afterward
var ErrTableCreatedNotFound = errors.NewKind("table was created but could not be found")

// ErrTableCreatedNotFound is thrown when an integrator attempts to create a temporary tables without temporary table
// support.
var ErrTemporaryTableNotSupported = errors.NewKind("database does not support temporary tables")
Copy link
Member

Choose a reason for hiding this comment

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

Put this in sql/errors.go

sql/plan/ddl.go Outdated
// support.
var ErrTemporaryTableNotSupported = errors.NewKind("database does not support temporary tables")

type IfNotExistsOperator bool
Copy link
Member

Choose a reason for hiding this comment

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

Not an operator

How about IfNotExistsOption?

And TempTableOption

@@ -150,6 +150,10 @@ func (partitionable) Schema() sql.Schema {

func (partitionable) Name() string { return "partitionable" }

func (partitionable) IsTemporary() bool {
Copy link
Member

Choose a reason for hiding this comment

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

From the dolt PR, you should define a new TemporaryTable interface extension to Table interface so that not every table implementation needs to provide IsTemporary

@VinaiRachakonda VinaiRachakonda merged commit 21cac24 into master Jun 2, 2021
@Hydrocharged Hydrocharged deleted the vinai/temporary-tables branch December 8, 2021 07:08
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.

2 participants