Skip to content

Replying to client’s queries SELECT @@AUTOCOMMIT without need of backend #4888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: v3.0
Choose a base branch
from

Conversation

yashwantsahu20
Copy link
Contributor

@yashwantsahu20 yashwantsahu20 commented Mar 26, 2025

Replying to client’s queries SELECT @@autocommit without need of backend
The query should also not disabling multiplexing.

For details Please see:
https://github.com/ProxySQL/proxysql_3p_testing/issues/13

…end. Returning from session object.

2. Added tap test.
@renecannao
Copy link
Contributor

Can one of the admins verify this patch?

@yashwantsahu20
Copy link
Contributor Author

Please ignore first commit message. As incorrectly I have mention SELECT @@Version instead of SELECT @@autocommit

@renecannao
Copy link
Contributor

add to whitelist

@yashwantsahu20 yashwantsahu20 changed the title [WIP] Replying to client’s queries SELECT @@AUTOCOMMIT without need of backend Replying to client’s queries SELECT @@AUTOCOMMIT without need of backend Mar 27, 2025
@renecannao
Copy link
Contributor

Initial requirement:

Reply to client’s queries SELECT @@AUTOCOMMIT (and also lowercase) returning the value of autocommit defined at MySQL session level, without the need of any backend. For reference, we already have a similar implementation for SELECT LAST_INSERT_ID() . The query should also not disable multiplexing. The implementation also requires adequate TAP test to verify the functionality .

const char* expected[] = {"1", "0", "1"};
int expected_idx = 0;

for (int i = 0; i < 5; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can avoid hardcoding the number of queries, but consider the size of states[]

Same thing applies for plan() : it can be computed based on the content of states[] .

The above consideration is related to the fact that:

  1. autocommit is changed from 1 (implicit) to 0 and then to 1 (explicitly), but never changed back to 0 (and eventually back to 1) to test multiple changes
  2. queries all have SELECT uppercase and autocommit lowercase : no combination of uppercase and lowercase are tested
  3. values 0 and 1 are used , while ON/OFF/true/FaLsE/etc are not tested

The test doesn't verify that no backend was used, neither that multiplexing was not disabled.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to propose to reuse other test for this purpose. All the feedback from the previous comment can be taken into modifying a test like reg_test_3549-autocommit_tracking-t.cpp which performs more complex queries, and already tracks autocommit, so should be a matter of doing an (extra) consistency check between the present tracking and SELECT @@autocommit. For addressing the part of the feedback about multiplexing disabling, the utility function check_multiplexing_disabled from test_keep_multiplexing_variables-t.cpp can also be moved to utils.cpp and reused.

return exit_status();
}

MYSQL_QUERY(mysql, "USE test");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious: why this?

If used to add come entropy, we could run after every SET/SELECT

myds->DSS=STATE_QUERY_SENT_DS;
int sid=1;
myprot->generate_pkt_column_count(true,NULL,NULL,sid,1); sid++;
myprot->generate_pkt_field(true,NULL,NULL,sid,(char *)"",(char *)"",(char *)"",buf2,(char *)"",63,31,MYSQL_TYPE_LONGLONG,161,0,false,0,NULL); sid++;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on a response from MySQL 5.7.44-log:

    Packet Length: 34
    Packet Number: 2
    Catalog
        Catalog: def
    Database
        Database:
    Table
        Table:
    Original table
        Original table:
    Name
        Name: @@autocommit
    Original name
        Original name:
    Charset number: binary COLLATE binary (63)
    Length: 1
    Type: FIELD_TYPE_LONGLONG (8)
    Flags: 0x0080
        .... .... .... ...0 = Not null: Not set
        .... .... .... ..0. = Primary key: Not set
        .... .... .... .0.. = Unique key: Not set
        .... .... .... 0... = Multiple key: Not set
        .... .... ...0 .... = Blob: Not set
        .... .... ..0. .... = Unsigned: Not set
        .... .... .0.. .... = Zero fill: Not set
        .... ...0 .... .... = Enum: Not set
        .... ..0. .... .... = Auto increment: Not set
        .... .0.. .... .... = Timestamp: Not set
        .... 0... .... .... = Set: Not set
    Decimals: 0
MySQL Protocol - row packet
    Packet Length: 2
    Packet Number: 3
    text
        text: 1
  • Size for the field of 1 instead of 31. Most probably this won't be an issue, yet this could be confusing from client side.
  • Flags should be 0x80 (binary_flag), instead of (0xa1).

const char* expected[] = {"1", "0", "1"};
int expected_idx = 0;

for (int i = 0; i < 5; ++i) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to propose to reuse other test for this purpose. All the feedback from the previous comment can be taken into modifying a test like reg_test_3549-autocommit_tracking-t.cpp which performs more complex queries, and already tracks autocommit, so should be a matter of doing an (extra) consistency check between the present tracking and SELECT @@autocommit. For addressing the part of the feedback about multiplexing disabling, the utility function check_multiplexing_disabled from test_keep_multiplexing_variables-t.cpp can also be moved to utils.cpp and reused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants