[MDEV-14594] Intermittent no results from query Created: 2017-12-05  Updated: 2017-12-11  Resolved: 2017-12-11

Status: Closed
Project: MariaDB Server
Component/s: Server
Affects Version/s: 5.5.52
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Robert G Assignee: Unassigned
Resolution: Not a Bug Votes: 0
Labels: None
Environment:

Linux


Attachments: File stripped_down.pcapng    

 Description   

I have a query. The query usually succeeds when executed from MySql Workbench and usually fails when executed with Python pymysql library.

The query is as follows:

SELECT ID, MAX(c) AS changes_in_result, COUNT(c) AS executions
        FROM (
            SELECT IF(@currvalue = ID, IF(@p = Result, @c, @c:=@c+1), @c:=0) AS c,
                 SUBSTRING_INDEX(ID, '/', -2) AS ID,
            (@p:=Result),
            @currvalue := ID AS whatever
        FROM test.suite_results AS t,
        (SELECT @p:=0, @currcount:=NULL, @currvalue:=NULL) AS _init
        WHERE Feature = 'comms'
        AND RTM_Finish >= DATE_SUB(CURDATE(),INTERVAL 28 day)
        order by ID, RTM_Finish DESC
        ) AS sub
        GROUP BY ID
        HAVING changes_in_result > 0
        ORDER BY changes_in_result DESC

The query should return string, followed by float, followed by long.
I've captured communication between client and server and while the query looks identical in both cases, the response is different:

  • in successful case, the fields are returned as expected
  • in unsuccessful case, the second field is indicated as BLOB with length of "00 00 00 01" (> 16 mln) and two response fields with EOF marker (254)

All of that implies that there's something tricky with the server.
I'm sorry I couldn't provide more details, but some of them might be too sensitive to share (my employer).
I haven't had a chance to verify on latest version (5.5.58).

By the way, I've almost forgotten.
Removing HAVING from the end makes it working in both environments. So far 100%.

I can try to provide at least wireshark dumps (where they don't reveal anything).
And the database/table structure.

I'm reporting it early to not forget about it (when having the workaround).

Regards,
Robert



 Comments   
Comment by Elena Stepanova [ 2017-12-11 ]

It is documented explicitly both in MariaDB KB and MySQL manual that assigning and using variables in the same SELECT statement is unsafe and can cause unpredictable results.
MariaDB KB

It is unsafe to read a user-defined variable and set its value in the same statement (unless the command is SET), because the order of these actions is undefined.

MySQL manual

As a general rule, other than in SET statements, you should never assign a value to a user variable and read the value within the same statement.
<...>
For <...> statements, such as SELECT, you might get the results you expect, but this is not guaranteed

If you can reproduce a similar problem without using statements which are known to be non-deterministic, please comment and the issue will be re-opened.

Generated at Thu Feb 08 08:14:47 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.