Skip to content

Client send multiple "Prepare" commands for one query #348

@smiera

Description

@smiera

Here is a test example

    #[tokio::test]
    async fn test_query() {
        let pool = Pool::from_url("mysql://root:@localhost:3306/for_test").unwrap();
        let rows: Option<Row> = "SELECT * FROM for_test WHERE id = ?"
            .with((1,))
            .first(&pool)
            .await
            .unwrap();
        println!("{:?}", rows);
    }

and MySQL server general log for this code contains two "Prepare" commands:

2025-05-22T06:36:42.458200Z	  725 Connect	root@localhost on for_test using TCP/IP
2025-05-22T06:36:42.458786Z	  725 Query	SELECT @@max_allowed_packet,@@wait_timeout,@@socket
2025-05-22T06:36:42.459741Z	  726 Connect	root@localhost on for_test using Socket
2025-05-22T06:36:42.459943Z	  726 Query	SELECT @@max_allowed_packet,@@wait_timeout
2025-05-22T06:36:42.460224Z	  725 Quit	
2025-05-22T06:36:42.466828Z	  726 Prepare	SELECT * FROM for_test WHERE id = ?
2025-05-22T06:36:42.466987Z	  726 Prepare	SELECT * FROM for_test WHERE id = ?
2025-05-22T06:36:42.467092Z	  726 Execute	SELECT * FROM for_test WHERE id = 1

But this test example, does not create two "Prepare" commands:

    #[tokio::test]
    async fn test_insert() {
        let pool = Pool::from_url("mysql://root:@localhost:3306/for_test").unwrap();
        let result = "INSERT INTO for_test (name) VALUES (?);"
            .with(("test name",))
            .run(&pool)
            .await
            .unwrap();
        println!("{:?}", result);
    }
2025-05-22T06:41:38.163937Z	  735 Connect	root@localhost on for_test using TCP/IP
2025-05-22T06:41:38.164364Z	  735 Query	SELECT @@max_allowed_packet,@@wait_timeout,@@socket
2025-05-22T06:41:38.165084Z	  736 Connect	root@localhost on for_test using Socket
2025-05-22T06:41:38.165411Z	  736 Query	SELECT @@max_allowed_packet,@@wait_timeout
2025-05-22T06:41:38.170577Z	  735 Quit	
2025-05-22T06:41:38.170904Z	  736 Prepare	INSERT INTO for_test (name) VALUES (?)
2025-05-22T06:41:38.170979Z	  736 Execute	INSERT INTO for_test (name) VALUES ('test name')

Is this is a bug, or I don't understand something?

Versions:

  • mysql_async = { version = "0.36.0", features = ["derive"]}
  • MySQL: 8.4.3-3 Homebrew

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions