Page MenuHomePhabricator

Database->insertSelect() generates invalid SQL when * is passed as $conds
Closed, ResolvedPublic

Description

According to InsertSelect documentation:

$conds Condition array. See $conds in IDatabase::select() for the details of the format of condition arrays. May be "*" to copy the whole table.

However, passing '*' to the $conds array causes an exception because it tries to generate a query that looks like this:
SELECT (fields) FROM (table) WHERE * FOR UPDATE

Since this is not from a command line, it tries to do a select first and then an insert, instead of a native insert select.

The following methods of Database class are handling the "*" correctly in $conds:

  • update
  • deleteJoin
  • delete

This looks like a regression, because there are extensions using it example. But I don't know for how long it's broken...

I see it a bit inconsistent that some methods accept an empty $conds for a full select, and other accept *.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptAug 22 2018, 4:20 PM

@daniel Is this possibly related to changes that you've been making?

Reedy added a subscriber: Reedy.Sep 17 2018, 8:38 PM

For reference, which DB type? And CLI or Web?

For reference, which DB type? And CLI or Web?

Mysql and web

aaron added a subscriber: aaron.Oct 1 2018, 9:22 PM

I think any callers should use '', not '*', which doesn't make much sense to me. That said, we already started the pattern, so it may as well work here too.

Change 463849 had a related patch set uploaded (by Aaron Schulz; owner: Aaron Schulz):
[mediawiki/core@master] rdbms: make * consistently act like in select/insertSelect methods

https://gerrit.wikimedia.org/r/463849

Krinkle assigned this task to aaron.Oct 2 2018, 4:29 PM
Krinkle triaged this task as Normal priority.

Change 463849 merged by jenkins-bot:
[mediawiki/core@master] rdbms: make * consistently act like in select/insertSelect methods

https://gerrit.wikimedia.org/r/463849

aaron closed this task as Resolved.Oct 16 2018, 9:37 PM