Confusion About SQL Execution Status

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: SQL执行状态疑惑

| username: 等一分钟

The same SQL, the first one is executed by the program and is very slow, the second one is executed using Navicat and takes about 30 seconds. Is there any difference in the state?

| username: Miracle | Original post link

Check the execution plans of the two SQLs in the slow log.

| username: 等一分钟 | Original post link

The image is not visible. Please provide the text you need translated.

| username: 等一分钟 | Original post link

Not finished yet.

| username: Miracle | Original post link

Is this section of code in the program displaying a transaction?

| username: 等一分钟 | Original post link

Do you mean whether the “begin” has been initiated?

| username: 等一分钟 | Original post link

I started begin in Navicat
image

It was also very fast.

| username: 像风一样的男子 | Original post link

The second execution might be faster because the cache is working.

| username: 等一分钟 | Original post link

It’s not the second time that’s fast; it’s the program execution that’s very slow. When I use Navicat, it’s very fast. The only difference is in the state column.

| username: 像风一样的男子 | Original post link

Could you post the execution plans for the two different results?

| username: 等一分钟 | Original post link

Hold on, the slow SQL hasn’t finished yet.

| username: Miracle | Original post link

My guess is that the transaction in the program did not explicitly end…

| username: 等一分钟 | Original post link

Cursor, how can there be a cursor?

| username: 等一分钟 | Original post link

Experts, how do you solve this problem?

| username: heiwandou | Original post link

Check the program and network.

| username: 等一分钟 | Original post link

There’s no problem with the network, what does the program need to check?

| username: 等一分钟 | Original post link

Is there any impact if the SQL executed by the program and the SQL executed using Navicat are different in terms of “in transaction; cursor exists”?

| username: Billmay表妹 | Original post link

Is the SQL the same? Blind guess, did Navicat include a limit?

| username: 等一分钟 | Original post link

SQL is the same, Navicat does not include LIMIT.

| username: 芮芮是产品 | Original post link

The first time it was slow, the program had concurrency, and occasionally there were some slowdowns.