Problem / motivation
SqlBase source plugin has the following configuration option:
- ignore_map: (optional) Source data is joined to the map table by default. If set to TRUE, the map table will not be joined.
If the SQL query uses expressions, the ignore_map option must be set because expressions with aliases cannot be used with JOINs.
Proposed resolution
Document this to SqlBase source plugin API documentation.
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | interdiff-2949378-13-16.txt | 1.02 KB | masipila |
| #16 | 2949378-16.patch | 1.14 KB | masipila |
| #13 | 2949378-13.patch | 1.13 KB | masipila |
| #8 | interdiff-2949378-3-8.txt | 1.3 KB | masipila |
| #8 | 2949378-8.patch | 1.15 KB | masipila |
Comments
Comment #2
heddnhttps://stackoverflow.com/questions/11685310/mysql-using-inner-joins-on-...
Sql error: Unknown column 'foo' in 'on clause'
Comment #3
masipila commentedThanks heddn for providing the SQL error message here so that if somebody is googling with the error message, they can find this issue.
Attached is a patch that adds this to API documentation.
Since this is documentation only, I'm proposing this to be cherry picked to 8.5.x.
Markus
Comment #4
heddnI want to work on the wording, but we should include why ignore map exists (slows performance, but improves SQL validity in certain cases). And we should point off to the SQL handbook if that works in the overall flow of things. On my phone, so I'll work on that later.
Comment #5
heddnignore_map: (optional) Source data is joined to the map table by default. If set to TRUE, the map table will not be joined. Set to FALSE if the sql has an expression added to it which will result in invalid SQL. Mapping helps speed up migration performance, but if it results in invalid SQL, then just disable it to retain valid SQL.
https://dev.mysql.com/doc/refman/en/join.html
https://dev.mysql.com/doc/refman/en/problems-with-alias.html
An example of invalid query when ignore_map: true is set:
Comment #6
masipila commentedHi,
Was your idea that we would add both those quotes to the actual docblock? There's no way to add quotes (blockquote tags) in the docblocks.
We should be able to explain this whole thing in a bit less verbose way. I'm not afraid of using lots of words to explain complex things but the amount of text we have in #5 is about the same as what we have for the database connection determination which is by far a bigger topic in this context.
So how about just this:
--clips--
ignore_map: (optional) Source data is joined to the map table by default to improve migration performance. If set to TRUE, the map table will not be joined. If the SQL query uses expressions (e.g. current date), the ignore_map option must be set to TRUE because expressions with aliases will result in invalid SQL.
--clips--
Markus
Comment #7
heddnI'm much more +1 on your version. I just wanted to get all the docs together in a single place so we have them as a reference.
Comment #8
masipila commentedComment #9
heddnThis seems like additional clarity on the docs. +1 on RTBC, but I wrote good parts so I'll leave to someone else.
Comment #10
phenaproximaI took a look at \Drupal\Core\Database\Query\Select and I think that we can make this even better. I do think we should document it, but we should also take advantage of Select::getExpressions() and automatically set ignore_map to TRUE if there are any expressions attached to the query. Then we can simply document that behavior.
Something like this might work:
Comment #11
heddnI feel like someone could write an addExpression() query that results in valid SQL in a JOIN. I'm not sure how to articulate that thought without making it so techno-bable and conditional that it has zero meaning.
Comment #12
heddnI did some digging, and it does seem possible. The other tricky thing, this whole thing is only important if the value in the expression is also part of the source id in
getIds(). If it isn't part of the IDs, then it doesn't matter about the ignore_map.Comment #13
masipila commentedHi,
I loved phenaproxima's suggestion in #10. However, if the expressions do not *always* result into invalid SQL as pointed out by @heddn, then the documentation should be sufficient and trying to automatically detect this goes quite complex compared to the benefit.
Please find attached a new patch which tries to describe the situation with the latest information. Interdiff doesn't add too much value since we are talking about the whole sentence here.
Markus
Comment #14
heddnI think this is closer what I'd want to say. We have the key words in there of invalid SQL and joins. So hopefully if someone runs into invalid SQL on the join, they can figure out to try setting ignore_map to true.
Since none of the wording is really at all what I wrote, I think I can now mark RTBC.
Comment #15
phenaproximaOne tiny thing, then +1 to RTBC.
Should be "...column aliases in the JOIN clause..."
Comment #16
masipila commentedThis should do it.
Comment #17
heddnComment #18
alexpottCommitted 1b87d95 and pushed to 8.6.x. Thanks!
Leaving to port to 8.5.x
Comment #20
alexpottCommitted f073033 and pushed to 8.5.x. Thanks!