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

support SELECT ... INTO OUTFILE/DUMPFILE ... #2317

Merged
merged 31 commits into from
Feb 9, 2024
Merged

support SELECT ... INTO OUTFILE/DUMPFILE ... #2317

merged 31 commits into from
Feb 9, 2024

Conversation

jycor
Copy link
Contributor

@jycor jycor commented Feb 6, 2024

This adds support for MySQL's SELECT ... INTO OUTFILE/DUMPFILE ... feature.
It is the complement to LOAD DATA. There is no LOCAL option, so files created using this feature are on the server.

This PR adds a custom TestSuite for testing these files, as it needs to write, read, and delete files.

syntax: dolthub/vitess#311
fixes dolthub/dolt#7453

sql/rowexec/rel.go Outdated Show resolved Hide resolved
Comment on lines 542 to 544
if _, relErr := filepath.Rel(dir.(string), fileStr); relErr != nil {
return sql.ErrSecureFilePriv.New()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a different check than we do on the load data infile parameter. In particular, the check we preform there has the following behavior differences:

  1. It doesn't allow creating files in subdirectories of secure_file_priv
  2. It uses os.Open + Stat() on the filepath.Dir() of the provided path, in addition to a Stat of the secure_file_priv directory, to assert that the files are in the same directory.

The end result is a difference in behavior when there are subdirectories, symlinks, etc. We should probably stick to the same behavior as the read paths?

Copy link
Contributor Author

@jycor jycor Feb 9, 2024

Choose a reason for hiding this comment

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

This should be fixed now through the isUnderSecureFileDir() function.
It checks that either the secure_file_privs directory and the outfile directory are the same or that the absolute path of secure_file_privs is a prefix to the absolute path of the outfile.

Copy link
Contributor

@fulghum fulghum left a comment

Choose a reason for hiding this comment

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

Looking pretty good. Some follow ups before merging in, but they all seem pretty straightforward. Happy to take another look at anything before you merge if you want.

sql/planbuilder/dml.go Outdated Show resolved Hide resolved
sql/planbuilder/dml.go Outdated Show resolved Hide resolved
sql/plan/load_data.go Outdated Show resolved Hide resolved
sql/rowexec/rel.go Outdated Show resolved Hide resolved
sql/rowexec/rel.go Outdated Show resolved Hide resolved
sql/plan/into.go Outdated Show resolved Hide resolved
enginetest/enginetests.go Outdated Show resolved Hide resolved
Copy link
Contributor

@fulghum fulghum left a comment

Choose a reason for hiding this comment

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

LGTM!

@jycor jycor merged commit 50fb2b2 into main Feb 9, 2024
7 checks passed
@jycor jycor deleted the james/select-into branch February 9, 2024 08:37
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.

Add support for "SELECT INTO" for files
3 participants