Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
postgresql db driver
Priority:
Major
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
15 Oct 2014 at 12:20 UTC
Updated:
2 Apr 2015 at 07:55 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
bzrudi71 commentedComment #2
bzrudi71 commentedAmbiguous column errors and some others...
Comment #3
bzrudi71 commentedUpdated test results for the views tests. As a side note: The fails in the search tests are caused by ambiguous column errors and will be fixed by #2192877: File content list includes ambiguous column fid in Group By statement as well as CacheTagsTests. Also attached a patch for the broken AreaTitleWebTest as a first start.
Comment #4
xjmI don't think we should be adding a
mt_rand()call here. Also, asserting a random value does not exist introduces a risk of random failures when the condition happens to be true, so this does not necessarily seem like the right fix.Why exactly is this change needed to get Postgres passing? What is invalid about 042118160112?
Comment #5
bzrudi71 commented@xjm: Thanks for review!
The test is about testing a non existing value:
But PostgreSQL is not happy with that value:
So I thouht using a high random (valid) integer value should be save.
Comment #6
xjmAh, I see, so the value is larger than the field allows in Postgres. @dawehner will be sad. :)
I checked in this test (see ViewTestBase::enableViewsTestModule()). The schema for this table is retrieved from state in views_test_data_schema(). The schema is defined by ViewTestData::schemaDefinition(), and the dataset is provided by ViewTestData::dataSet().
So the ID field is an autoincremented field, with five rows by default. Setting it to a high value seems reasonable, but with a negative assertion, it seems like it would be better to assert a specific value that does not exist, so we know immediately in the future if the dataset changes, to avoid the risk of either a random fail or a false positive. Pairing it with a true assertion (for valid data) will verify this.
Patch attached. :) Let us know if this still fixes the fail on postgres.
Comment #7
bzrudi71 commentedGreat, this seems like a much better fix for the issue and yes, tests still pass PG bot :-) Thanks a lot @xjm! Attached updated test results for the views test group.
@xjm: We have a fail strange fail in RelationshipRepresentativNodeTest() that drives me crazy. It fails with:
Obviously there is something wrong with the INNER statements, I just can't figure out where exactly this happens due to the complexity in views ;-) Any idea?
BTW I'm offline until Wednesday...
Comment #8
xjmSo here is what the generated query looks like on MySQL:
So looking at that test, my first guess is looking at what's weird/special about that test view, which is the
groupwise_maxplugin. I started by looking in there, and theINNERare actually being added deliberately for namespacing the field... they're not for joins actually! See in the GroupwiseMax Views plugin.I have two guesses -- either postgres does not support groupwise max the same way that mysql does, or INNER is being caught as a keyword even though it's actually being part of the field/table aliases?
Comment #9
jaredsmith commentedOK, so it's good to know that the query is *mostly* the same, whether on MySQL or PostgreSQL -- in fact, when I take the MySQL query and run it manually on PostgreSQL, I get the same error.
The error seems to be tied to the condition in the WHERE clause... namely:
WHERE taxonomy_term_data_node__taxonomy_term_field_dataINNER.tid = taxonomy_term_field_data.tidPostgreSQL is complaining that there's no FROM clause for the taxonomy_term_field_data table. I'm a bit unclear on what the intention of the query itself is here, but I can see two possible scenarios:
In short, the query *works* on MySQL, but I'm not sure it's doing what it's actually supposed to be doing.
Any clarification you can add would be helpful -- this is my first time trying to debug Views sql statements.
Comment #10
xjmWell, not exactly -- they're two different aliases for the same table. So it's saying "In the subquery, pick the node with the maximum nid for the term with the tid that matches each one in the ON statement from the outer query." I think. :)
Original feature request: #470258: Groupwise maximum ('representative') relationships
When it was broken before the VDC merge: #1799040: Fixed groupwise max relationship
A way to test the view is by copying the config from views.view.test_groupwise_term.yml into the "single import" for config at
/admin/config/development/configuration/single/import. Just to make sure the feature is actually working on MySQL still, I created taxonomy terms 'red', 'blue', and 'yellow'; and tagged miscellaneous nodes with these colors. The view showed a single row with each color, in each case the node with the highest nid tagged with that color.Comment #11
xjmBTW, reading GroupwiseMax::leftQuery() is... classic. Maybe around line 294 is where the
unrecognized aliastable name is getting substituted in? There's a note there specifically that it's deliberately circumventingSelectQuery.Comment #12
xjmFWIW, I would be unopposed to moving this particular plugin into contrib if we can't get it working on Postgres/SQLite but we get everything else working on those databases. So it might be best to fix other Views failures first, and file a separate issue for GroupwiseMax being broken on Postgres. (I'd also be interested to know whether it works on SQLite in that issue.)
Comment #13
xjmAlso #1417090-20: Taxonomy term "Representative node" views with filters and sorts don't work might be relevant.Comment #14
xjmActually here is that patch for D8: #2379423: Representative Node Views fails due to invalid SQL
Comment #15
jaredsmith commentedThe patch from #2379423: Representative Node Views fails due to invalid SQL makes no difference on the tests on PostgreSQL using the drupalci infrastructure. I've attached a list of the tests, and it is exactly the same with or without that patch. So I'm going to set that aside for a moment, and dive back into the query itself.
I better understand what's going on with the query now -- and I have some ideas. First, I've found that the reason that the reference to the taxonomy_term_field_data table is failing in PostgreSQL is that the taxonomy_term_field_data table doesn't get joined until after the subquery. If I move the INNER JOIN (on the taxonomy_term_field_data table) above the LEFT JOIN (which contains the subquery), then the query works as expected in both PostgreSQL and MySQL.
My second comment (which probably belongs somewhere else in its own issue) is that using a correlated subquery to find the groupwise maximum is usually fairly inefficient, as the subquery has to run for each row returned by the outer query. A more efficient method is typically to use a self-JOIN and a HAVING clause to filter out all but the requested record per group.
For example, assuming you have a table of countries (with the name of the country, it's population, and its continent -- just like the sample MySQL data available at https://dev.mysql.com/doc/world-setup/en/) and you want to find the country with the highest population in each continent, you could use the following query:
Also, PostgreSQL has a more efficient syntax for creating a groupwise maximum... the DISTINCT ON syntax. The same query above would be rewritten as follows to use the DISTINCT ON syntax:
I haven't begun to wrap my head around how to fix this Views plugin to do the right thing here, but I'm leaving this information in hopes that someone else will come along and know what to do.
Comment #16
mradcliffeThis is related to capital letters issue, but the patch in that issue didn't fix this. As soon as I quote/escape those table aliases, the query works.
Adding escaping in addJoin would require a lot of string manipulation because the $condition argument is a string provided by the caller. I don't know about stuffing more things into the driver, which was my first approach, but the Views plugin could do the escaping first as well in the patch in the linked issue.
I'll make this comment over there as well.
Comment #17
bzrudi71 commentedComment #18
bzrudi71 commentedCreated all required sub-issues.
Comment #19
jaredsmith commentedI tried this, but it didn't work for me, even when the table names and aliases were quoted.
Comment #20
bzrudi71 commentedAdded #2451749: PostgreSQL: Fix views\src\Tests\GlossaryTest.php.
Comment #21
bzrudi71 commentedArgh, I like closing issues much better :-(
Added #2452943: PostgreSQL: Fix views\Tests\Handler\FieldGroupRowsWebTest caused by #2342045: Standard views base fields need to use same rendering as Field UI fields, for formatting, access checking, and translation consistency.
Comment #22
bzrudi71 commentedAdding #2462747: PostgreSQL: Fix views\Tests\ModuleTest :-(
Comment #23
bzrudi71 commented