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

No way to access granular results from LOAD DATA #1179

Open
droberts-sea opened this issue Dec 4, 2020 · 1 comment
Open

No way to access granular results from LOAD DATA #1179

droberts-sea opened this issue Dec 4, 2020 · 1 comment

Comments

@droberts-sea
Copy link

Issue description

This began life as a question on StackOverflow. Discussion is copied here for ease of access.

Question

I am writing a Go program that interacts with a MySQL database. In MySQL, when you do a LOAD DATA query, in addition to the regular X rows affected line you get a line with more granular information:

mysql> LOAD DATA LOCAL INFILE 'many-lines.tsv' REPLACE INTO TABLE test_table (id, timestamp);
Query OK, 6 rows affected (0.01 sec)
Records: 3  Deleted: 3  Skipped: 0  Warnings: 0

As documented here under the section "Statement Result Information".

I would love to be able to access this from my Go program, but I cannot figure out how, or whether it's even possible. sql.DB.Exec() returns a Result, but that only has a RowsAffected field. This contains a sum of rows written + rows deleted and ignores rows skipped, and is therefore ambiguous (write 3, delete 2 and skip 2 is the same as write 5, delete 0 and skip 0).

I looked through the documentation for the Go MySQL driver, but couldn't find anything there that does what I want.

Is there a way to get access to this information?

Answer

The information is actually a ER_LOAD_INFO "error" (notionally info) message of the server.

This gets communicated as an informational message in the OK response from the server.

Looking at the decoding of the OK packet in go, it isn't parsing out the info (human readable status information). When making the connection ensure that clientSessionTrack is part of the connection flags.

So a few small enhancements to the Go MySQL driver and you'll be able to access it.

Example code

N/A

Error log

N/A

Configuration

Driver version (or git SHA): v1.4.1

Go version:

$ go version
go version go1.15.2 darwin/amd64

Server version:
Server OS:

mysql> SHOW VARIABLES LIKE "%version%";
+-------------------------+------------------------------+
| Variable_name           | Value                        |
+-------------------------+------------------------------+
| innodb_version          | 5.6.50                       |
| protocol_version        | 10                           |
| slave_type_conversions  |                              |
| version                 | 5.6.50                       |
| version_comment         | MySQL Community Server (GPL) |
| version_compile_machine | x86_64                       |
| version_compile_os      | Linux                        |
+-------------------------+------------------------------+
7 rows in set (0.02 sec)
@yosefy
Copy link

yosefy commented Feb 6, 2023

just asking, is it anywhere on the roadmap?

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

No branches or pull requests

2 participants