Skip to content

Conversation

mbeijen
Copy link

@mbeijen mbeijen commented Sep 30, 2023

I found the data format created by mysqldump slightly annoying. By default the INSERT INTO values are all on one very long line. This fix solves the issue.

What I found very interesting is that the comment read 'Always row break' but there was never a row break, so the code was not doing what it said. That is the 'naive' place to put the line break, so all rows terminate with a newline. I opted to put the newline at the beginning of the line instead, so also the first row goes on its own line.

if (extended_insert) {
size_t row_length;
dynstr_append_checked(&extended_row, ")");
row_length = 2 + extended_row.length;
if (total_length + row_length < opt_net_buffer_length) {
total_length += row_length;
fputc(',', md_result_file); /* Always row break */

This is the output without the patch:

--
-- Dumping data for table `category`
--

LOCK TABLES `category` WRITE;
/*!40000 ALTER TABLE `category` DISABLE KEYS */;
INSERT INTO `category` VALUES (1,'Action','2006-02-15 04:46:27'),(2,'Animation','2006-02-15 04:46:27'),(3,'Children','2006-02-15 04:46:27'),(4,'Classics','2006-02-15 04:46:27'),(5,'Comedy','2006-02-15 04:46:27'),(6,'Documentary','2006-02-15 04:46:27'),(7,'Drama','2006-02-15 04:46:27'),(8,'Family','2006-02-15 04:46:27'),(9,'Foreign','2006-02-15 04:46:27'),(10,'Games','2006-02-15 04:46:27'),(11,'Horror','2006-02-15 04:46:27'),(12,'Music','2006-02-15 04:46:27'),(13,'New','2006-02-15 04:46:27'),(14,'Sci-Fi','2006-02-15 04:46:27'),(15,'Sports','2006-02-15 04:46:27'),(16,'Travel','2006-02-15 04:46:27');

and this is with the patch:

--
-- Dumping data for table `category`
--

LOCK TABLES `category` WRITE;
/*!40000 ALTER TABLE `category` DISABLE KEYS */;
INSERT INTO `category` VALUES
(1,'Action','2006-02-15 04:46:27'),
(2,'Animation','2006-02-15 04:46:27'),
(3,'Children','2006-02-15 04:46:27'),
(4,'Classics','2006-02-15 04:46:27'),
(5,'Comedy','2006-02-15 04:46:27'),
...

much easier to handle.

After I created the patch, I found this enhancement request concerning this issue:
https://bugs.mysql.com/bug.php?id=65465

@mysql-oca-bot
Copy link

Hi, thank you for submitting this pull request. In order to consider your code we need you to sign the Oracle Contribution Agreement (OCA). Please review the details and follow the instructions at https://oca.opensource.oracle.com/
Please make sure to include your MySQL bug system user (email) in the returned form.
Thanks

It's interesting to see that at the end of the row there was a comment
that read 'Always row break' but there actually was no 'row break'.
It appears as if the idea _was_ that there was a newline after each row
of data, increasing the readability of the dump files.

However I opted to put the newline character _before_ the line instead,
so also the first row of output is on a separate line from the INSERT
statement.

Fixes https://bugs.mysql.com/bug.php?id=65465
@mbeijen mbeijen force-pushed the mysqldump-row-break branch from 0f337d9 to 2cfb911 Compare September 30, 2023 10:08
@mbeijen mbeijen changed the title mysqldump: add line break after each database row mysqldump: add line break before each database row Sep 30, 2023
@mysql-oca-bot
Copy link

Hi, thank you for your contribution. Please confirm this code is submitted under the terms of the OCA (Oracle's Contribution Agreement) you have previously signed by cutting and pasting the following text as a comment:
"I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it."
Thanks

@mbeijen
Copy link
Author

mbeijen commented Oct 13, 2023

I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

@mysql-oca-bot
Copy link

Hi, thank you for your contribution. Your code has been assigned to an internal queue. Please follow
bug http://bugs.mysql.com/bug.php?id=112719 for updates.
Thanks

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