View Issue Details

IDProjectCategoryView StatusLast Update
0024561mantisbtplug-inspublic2018-07-15 12:13
Reporterfman Assigned Todregad  
PrioritynormalSeveritymajorReproducibilitysometimes
Status closedResolutionno change required 
Summary0024561: Sorting for Table Columns from a plugin Table Crashes on MySQL 5.7
Description

I've been developing a plugin, and need to add a Column from an specific custom plugin table on bug view.
I've used as a working model the TimeTracking plugin https://github.com/mantisbt-plugins/timetracking.

Doing tests with TimeTracking, an with my plugin gave OK, on my linux installation that uses MariaDB.
OK also on my MAMP PRO installation that uses MySQL 5.6.38.

A new QA environment on Windows was created using Bitnami WAMP 7.1.18 than installs:

  • Apache 2.4.33
    • MySQL 5.7.22
    • PHP 7.2.6

Then I face the error regarding the fact that a SELECT DISTINCT tries to order by a column not present on SELECT.
This happens because MantisBT seems to extract data ONLY from mantis_bug_table.

I've done several searches on google and seems that depending on how each kind of DBMS choose to manage this situation throwing the error can be right.
Because I'm not an SQL expert I'm asking you to give a look to this situation in order to understand if change has to be done on this query in order to be sure, it will work as expected no matter the DBMS used.

I'm going to post the offending query.

regards

TagsNo tags attached.

Activities

fman

fman

2018-06-23 14:23

reporter   ~0060133

Last edited: 2018-06-27 09:09

Here the error

Error received from database was #3065: Expression #2 of ORDER BY clause is not in SELECT list, references column 'SUBQ1.itil_priority' which is not in SELECT list; this is incompatible with DISTINCT for the query: 

SELECT DISTINCT mantis_bug_table.* FROM mantis_bug_table JOIN mantis_project_table 
ON mantis_project_table.id = mantis_bug_table.project_id 
LEFT OUTER JOIN ( 
SELECT TTB1.id, IP.itil_priority FROM mantis_bug_table TTB1 JOIN mantis_plugin_simpleITIL_incident_priority_table IP ON TTB1.id = IP.bug_id WHERE TTB1.project_id IN (1,17,28,44) GROUP BY TTB1.id ) SUBQ1 
ON mantis_bug_table.id = SUBQ1.id 
WHERE mantis_project_table.enabled =? AND (mantis_bug_table.project_id IN (?,?) OR mantis_bug_table.project_id IN (?,?) AND mantis_bug_table.view_state = ? OR mantis_bug_table.project_id IN (?,?) AND mantis_bug_table.reporter_id = ?) 
ORDER BY mantis_bug_table.sticky DESC, SUBQ1.itil_priority ASC, mantis_bug_table.due_date DESC, mantis_bug_table.last_updated DESC, mantis_bug_table.date_submitted DESC.
dregad

dregad

2018-06-27 09:16

developer   ~0060176

This is caused by MySQL's SQL mode which has more strict settings by default in 5.7. In this specific case, I think it's the only_full_group_by mode which is causing the error.

To fix the problem, I would just add itil_priority to the main SELECT DISTINCT, and you might need to add it to the GROUP BY clause in the subquery as well. I have not actually tested this, but in theory it should work with other RDBMS too, as this is standard SQL (older versions of MySQL were more permissive by default).

As a side note, you may want to optimize your main query's WHERE clause, to extract the mantis_bug_table.project_id IN (?,?) bit so it's only evaluated once instead of 3.

This is not a bug or feature request for MantisBT, so I am resolving this issue as "no change required".

fman

fman

2018-06-27 11:36

reporter   ~0060177

in order to add itil_priority is that this has to be done through some mechanism that today is not present with plugins.
I agree with you that the column can be added.
Your help on understanding why a distinct must be used will be great, may be is the distinct can be removed this issue may be can be solved without changing MySQL setting

Thanks for your help

dregad

dregad

2018-06-28 08:37

developer   ~0060186

this has to be done through some mechanism that today is not present with plugins

You did not provide any context as to how the SQL was generated.

may be is the distinct can be removed this issue may be can be solved without changing MySQL setting

Did you confirm that without the DISTINCT you don't get the error ?

fman

fman

2018-07-02 04:41

reporter   ~0060207

Hi,
My fault was not providing the context, you are absolutely right.

I'm going to check if things will work without and provide feedback

best regards

fman

fman

2018-07-04 14:21

reporter   ~0060214

here a link regarding only_full_group_by than maybe can be useful as future reference:
https://mysqlserverteam.com/mysql-5-7-only_full_group_by-improved-recognizing-functional-dependencies-enabled-by-default/