[MDEV-13300] Query cache doesn't take in account CLIENT_DEPRECATE_EOF capability Created: 2017-07-12  Updated: 2022-04-21  Resolved: 2017-08-09

Status: Closed
Project: MariaDB Server
Component/s: Query Cache
Affects Version/s: 10.2
Fix Version/s: 10.2.8

Type: Bug Priority: Critical
Reporter: Diego Dupin Assignee: Oleksandr Byelkin
Resolution: Fixed Votes: 1
Labels: None

Issue Links:
Problem/Incident
causes CONJ-504 java.lang.ArrayIndexOutOfBoundsExcept... Closed

 Description   

Query cache doesn't take in account capability CLIENT_DEPRECATE_EOF.

This flag change query result data : suppressing some EOF, or replacing some with OK_Packet for example.
Since query cache doesn't check this field in query cache data structure : https://mariadb.com/kb/en/mariadb/query-cache/#query-cache-internal-structure
corresponding source : https://github.com/MariaDB/server/blob/10.2/sql/sql_cache.cc#L1413

If a driver that doesn't set CLIENT_DEPRECATE_EOF capability execute a query that can be cached, another driver that support CLIENT_DEPRECATE_EOF will have a resultset in a format not expected if executing the same query. (the opposite is true too).

In term of error with java driver, resulting errors can be :

java.lang.ArrayIndexOutOfBoundsException: 5
	at org.mariadb.jdbc.internal.com.read.resultset.SelectResultSet.readNextValue(SelectResultSet.java:510)
	at org.mariadb.jdbc.internal.com.read.resultset.SelectResultSet.fetchAllResults(SelectResultSet.java:368)

or

java.sql.SQLException: (conn:28) Packets out of order when reading field packets, expected was EOF stream. Packet contents (hex) = XX

workaround is to disable query cache (see documentation) or to not mix drivers that support CLIENT_DEPRECATE_EOF with other that don't support this capability



 Comments   
Comment by Jamie Jackson [ 2017-07-13 ]

Please add 5.5.56 to the list of known affected versions (so 5.5.x is represented).

Comment by Elena Stepanova [ 2017-07-14 ]

Jamie Jackson, Could you please clarify how it affects 5.5?
The version has no knowledge of the capability, so no matter whether query cache is on or off, it won't be suppressing the EOF, thus no difference for capable/incapable clients.

Comment by Elena Stepanova [ 2017-07-14 ]

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.CallableStatement;
import java.sql.SQLException;
import java.sql.Types;
 
public class JConnectorTest2
{
    public static void main (String argv[])    
    {
        Connection conn;
        try {
            conn = DriverManager.getConnection("jdbc:mariadb://localhost:3306/test","root","");
            Statement st = conn.createStatement();
            st.execute("CREATE TABLE IF NOT EXISTS t1 (i INT) AS SELECT 1 AS i");
            st.execute("CREATE PROCEDURE IF NOT EXISTS pr (OUT x INT) SELECT * FROM t1");
            CallableStatement ps = conn.prepareCall("call pr(?)");
            ps.registerOutParameter(1, Types.INTEGER);
            ps.execute();
        }
        catch (Exception e)
        {
            System.out.println("Exception: " + e + "\n");
        }
    } 
}

Assuming that the server has been started on port 3306 with query_cache_type=1, query_cache_size=1048576, the database is empty and the query cache has been reset:

If I first run the above test with java-client 1.5.5, and then 2.0.3, then I get

Exception: java.lang.ArrayIndexOutOfBoundsException: 5

If I first run it with java-client 2.0.3, and then 1.5.5, then I get

Exception: java.sql.SQLException: (conn:56) Packets out of order when reading field packets, expected was EOF stream. Packet contents (hex) = 000001000000000100000000382D4D6172696144422D64656275670038000000645C2335224A304E00FEF7080200BF81150000000000000700000078353C6B29262276506D5540006D7973716C5F6E61746976655F70617373776F726400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Query is: call pr(?), parameters [<null>]

If I modify the test so that the table is empty (CREATE TABLE IF NOT EXISTS t1 (i INT) AS SELECT 1 AS i LIMIT 0), and run the test first with 2.0.3 and then 1.5.5, it hangs with 1.5.5.

Comment by Jamie Jackson [ 2017-07-14 ]

elenst, please see CONJ-491 (a 5.5 ticket), where diego dupin asserted that MDEV-13300 is the culprit.

Comment by Elena Stepanova [ 2017-07-14 ]

Jamie Jackson, thanks for the clarification.

diego dupin, sanja, I'll leave it to you to figure out between yourselves how this issue can affect 5.5, I don't get it. Please do update the Affects version/s if necessary.

Comment by Diego Dupin [ 2017-07-17 ]

Jamie Jackson, elenst, Sorry, I forgot that CONJ-491 was about this version of server (5.5). Since error corresponded perfectly to this issue, i've linked it too rapidely.

I've reopen the ticket CONJ-491 and un-link it to this error.
This issue (MDEV-13300) concern only 10.2 version.

Comment by Oleksandr Byelkin [ 2017-08-04 ]

revision-id: ccca8487b708fae5320c295938e8266860d81281 (mariadb-10.2.7-20-gccca8487b70)
parent(s): bcc10a5a447805ce64aa13ee6a037c1618219616
committer: Oleksandr Byelkin
timestamp: 2017-08-04 11:02:13 +0200
message:

MDEV-13300 Query cache doesn't take in account CLIENT_DEPRECATE_EOF capability

take into account new capabilty flag which has influence on result format.

Comment by Oleksandr Byelkin [ 2017-08-04 ]

github tree is bb-10.2-MDEV-13300

Comment by Oleksandr Byelkin [ 2017-08-04 ]

responded till I have time to understand java technology

Comment by Oleksandr Byelkin [ 2017-08-07 ]

Fix for Connector-J is confirmed. Connector-C has no support of this feature.

Comment by Sergei Golubchik [ 2017-08-09 ]

ok to push

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