Execution Plan

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

Original topic: 执行计划

| username: 胡杨树旁

I don’t quite understand the execution plan part. Why is the index on table b not used? Table m has 394 rows, and table b has 7397 rows.


SQL text: EXPLAIN ANALYZE SELECT
m.,
b.

FROM
PLC_RISKMAINCONFIG m,
PLC_RISKDETAILCOFIG b
WHERE
1 = 1
AND m.id = b.parentId
AND m.coeffCategoryTwoCode = ‘1’
AND m.viewFlag = ‘0’
AND b.intervalBig < ‘1’ AND b.intervalSmall > ‘1’
AND productcode = ‘27010001’

| username: Kongdom | Original post link

What is a B-table index?

| username: 胡杨树旁 | Original post link

The image is not available for translation. Please provide the text content directly.

| username: Kongdom | Original post link

The conditions for Table B are not in the index, right?

AND b.intervalBig < ‘1’ AND b.intervalSmall > ‘1’

| username: 胡杨树旁 | Original post link

I see that it is the b and m tables being joined. Why can’t you use the join condition m.id = b.parentId?

| username: Kongdom | Original post link

You can refer to this for understanding:

| username: h5n1 | Original post link

Are the types of the two fields consistent?

| username: 胡杨树旁 | Original post link

They are different. One is decimal and the other is varchar. In this case, the index cannot be used, right?

| username: h5n1 | Original post link

There will be implicit conversion, causing the index to be unusable.

| username: 胡杨树旁 | Original post link

So how do you convert this kind of thing to be the same?

| username: 考试没答案 | Original post link

b.interbig is used as the access method for table b, so indexes are not used. The associated column is converted back to the table and type after the condition. It is impossible to use indexes, right?

| username: 考试没答案 | Original post link

Converting ‘1’ to 1 removes the single quotes and recognizes it as a number. Adding single quotes makes it a character. For you, both are 1, but for the machine, the types are different.