Skip to content

[WIP] [DBAL-218] Add bulk insert query#682

Closed
deeky666 wants to merge 1 commit intodoctrine:4.0.xfrom
deeky666:DBAL-218
Closed

[WIP] [DBAL-218] Add bulk insert query#682
deeky666 wants to merge 1 commit intodoctrine:4.0.xfrom
deeky666:DBAL-218

Conversation

@deeky666
Copy link
Copy Markdown
Member

This is an approach to make use of database vendors' bulk row insert query syntax.
As the nature of bulk inserts usually is to insert a LOT of rows into a table (primarily from an external source), the implementation tries to focus on good performance and low memory consumption. It is NOT intended for INSERT INTO ... SELECT ... statement queries.

TODO:

  • Add an "executor" class that encapsulates the BulkInsertQuery object, adds options like bulk size and internally automatically evaluates the underlying platform's limits for a single INSERT statement and splits queries accordingly.
  • Evaluate platforms' max insert rows per INSERT statement and implement in platforms.
  • Add unit tests for quoted identifiers.
  • Add functional tests.

Future additions:

  • Add support for expressions.
  • Query builder (if there will be more bulk insert queries like INSERT INTO ... SELECT ...)?

Open for discussion. Ideas welcome!

@doctrinebot
Copy link
Copy Markdown

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DBAL-994

We use Jira to track the state of pull requests and the versions they got
included in.

@acrobat
Copy link
Copy Markdown
Contributor

acrobat commented Oct 3, 2014

👍 very good idea!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what is the meaning of 0 for a max ?

If there is no maximum, I think returning null might be more logical than 0. And 1 might be a better default in the abstract platform rather than unlimited

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hmm, no. Given that it throws an exception rather than splitting it into mutliple executions, unlimited is indeed a better default

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@stof the value specified in the platform should represent the platform semantics rather than what would be a reasonable default for mass insertions. In general platforms do not have a fixed limit for a single INSERT query, but SQL Server for example has. So unlimited is indeed correct here IMO. The BulkInsertExecutor I am still working on, will then split into multiple INSERT queries when added values reach the platforms maximum value.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

:hint: PHP supports INF :hint:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Ocramius not well. INF is equal to 0 on some OSes. See symfony/symfony#8246 for instance

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does this count?

http://phpsadness.com/sad/52

-----Original message-----
From: Marco Pivetta notifications@github.com
To: doctrine/dbal dbal@noreply.github.com
Cc: Eric Wastl topaz.github@lt3.us
Sent: 2014 Dec, Tue, 16 21:33:56 GMT+00:00
Subject: Re: [dbal] [WIP] [DBAL-218] Add bulk insert query (#682)

@@ -595,6 +595,16 @@ public function getBinaryDefaultLength()
}

 /**
  • \* Returns the maximum number of rows that can be inserted in a  
    
    single INSERT statement.
  • *
    
  • \* @return integer
    
  • */
    
  • public function getInsertMaxRows()
  • {
  •    return 0;
    

@topaz I'm talking about INF == 0 :) We're not that bad in doctrine (yet)


Reply to this email directly or view it on GitHub:
https://github.com/doctrine/dbal/pull/682/files#r21933752

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@topaz thanks, that is sad enough :-)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@topaz the issue is actually that on Solaris, we have INF === 0.0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think it is better to make this method abstract to avoid forgotten implementations in sub-classes and useless default values.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@edefimov not possible until a major version, as adding a new abstract method is a BC break.

@deeky666 deeky666 added this to the 2.6 milestone Oct 23, 2014
@Ocramius Ocramius removed this from the 2.6 milestone Dec 28, 2014
@deeky666 deeky666 removed this from the 2.6 milestone Dec 28, 2014
@billschaller
Copy link
Copy Markdown
Member

NEAT! I was wondering if something like this existed somewhere.

@aistis-
Copy link
Copy Markdown

aistis- commented Jul 5, 2016

Hi guys, any news?

@jonbev
Copy link
Copy Markdown

jonbev commented Aug 10, 2016

What's going on with this PR? Would be nice to get this merged....

@widmogrod
Copy link
Copy Markdown

Thats a nice feature. Is there anything that I can help to finish it?

{
$valueSet = array();

if (empty($this->columns)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I suggest to refactor method to increase readability

@Ocramius Ocramius added this to the 2.6 milestone Jun 29, 2017
@edefimov edefimov mentioned this pull request Jun 29, 2017
@Ocramius Ocramius modified the milestones: 2.6, 2.7 Jul 2, 2017
@Ocramius
Copy link
Copy Markdown
Member

Ocramius commented Jul 2, 2017

Moved to a later milestone: while 2.7 may not actually happen (3.0 is a better pick), this can't land in 2.6 yet, even though it is just an improvement.

@mbrodala
Copy link
Copy Markdown

What is the API for retrieving the list of all inserted record IDs?

@Ocramius
Copy link
Copy Markdown
Member

What is the API for retrieving the list of all inserted record IDs?

Won't be implemented.

@mbrodala
Copy link
Copy Markdown

I guess as a workaround one could retrieve the maximum ID before and after the bulk insert which would suffice to get the list of newly added IDs.

@Ocramius
Copy link
Copy Markdown
Member

Ocramius commented Nov 27, 2017 via email

@mbrodala
Copy link
Copy Markdown

@Ocramius OK, what else do you suggest in that case?

@Ocramius
Copy link
Copy Markdown
Member

Ocramius commented Nov 27, 2017 via email

@kiler129
Copy link
Copy Markdown

@Ocramius What prevents us from continuing with that? After reading all comments I see all problems were resolved.

@Majkl578
Copy link
Copy Markdown
Contributor

@kiler129 This is most likely to be superseded by #2762.

@Majkl578 Majkl578 modified the milestones: 2.7.0, 2.8.0 Mar 29, 2018
@Majkl578 Majkl578 modified the milestones: 2.8.0, 2.9.0 Jun 14, 2018
@morozov morozov removed this from the 2.9.0 milestone Dec 2, 2018
@wujku
Copy link
Copy Markdown

wujku commented Feb 13, 2019

👍

Base automatically changed from master to 4.0.x January 22, 2021 07:43
@morozov
Copy link
Copy Markdown
Member

morozov commented Oct 26, 2021

Closing as stale.

@morozov morozov closed this Oct 26, 2021
@matheusgontijo
Copy link
Copy Markdown

@morozov Was the bulk insert feature eventually implemented on Doctrine by any chance? Just for my information. Thank you so much.

@Koopzington
Copy link
Copy Markdown

Koopzington commented Nov 10, 2022

Doesn't look like it seeing how the "superseding" PR got closed as stale as well.

' VALUES(' . implode(', ', $this->values) . ')';

@speller
Copy link
Copy Markdown

speller commented Sep 4, 2023

So sad that this feature was not implemented after 9 years from the report....

@Ocramius
Copy link
Copy Markdown
Member

Ocramius commented Sep 4, 2023

@speller send a new PR?

@deeky666 , @morozov and myself are not really active on the project anymore, and OSS comes from YOU first.

Take the feature, champion for it, bring it to the finish line.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.