Answer the question
In order to leave comments, you need to log in
How can this sql code be optimized?
Now the execution of this code to issue 5 results is 10 seconds, but it takes much less, but what to do?
Simplified code:
SELECT
*
FROM
table_sql AS t0
INNER JOIN table_sql AS t1 ON (
t0.id <> t1.id
AND (
0
OR (
1
AND t0.P1_01 = t1.P1_01
AND t0.X_02 = t1.X_02
AND t0.X_01 = t1.X_01
AND t0.X_10 = t1.X_10
AND t0.P2_01 = t1.P2_01
)
OR (
1
AND t0.P1_01 = t1.P1_01
AND t0.X_02 = t1.X_02
AND t0.X_01 = t1.X_01
AND t0.X_10 = t1.X_10
)
OR (
1
AND t0.X_02 = t1.X_02
AND t0.X_01 = t1.X_01
AND t0.X_10 = t1.X_10
AND t0.P2_01 = t1.P2_01
)
)
)
ORDER BY
t0.date ASC
LIMIT
5
SELECT
*
FROM
table_sql AS t0
INNER JOIN table_sql AS t1 ON (
t0.id <> t1.id
AND (
0
OR (
1
AND t0.P1_01 = t1.P1_01
AND t0.X_02 = t1.X_02
AND t0.X_01 = t1.X_01
AND t0.X_10 = t1.X_10
AND t0.P2_01 = t1.P2_01
)
OR (
1
AND t0.P1_01 = t1.P1_01
AND t0.X_02 = t1.X_02
AND t0.X_01 = t1.X_01
AND t0.X_10 = t1.X_10
)
OR (
1
AND t0.X_02 = t1.X_02
AND t0.X_01 = t1.X_01
AND t0.X_10 = t1.X_10
AND t0.P2_01 = t1.P2_01
)
OR (
1
AND t0.P1_10 = t1.P1_10
AND t0.X_01 = t1.X_01
AND t0.X_10 = t1.X_10
AND t0.X_20 = t1.X_20
AND t0.P2_10 = t1.P2_10
)
OR (
1
AND t0.P1_10 = t1.P1_10
AND t0.X_01 = t1.X_01
AND t0.X_10 = t1.X_10
AND t0.X_20 = t1.X_20
)
OR (
1
AND t0.X_01 = t1.X_01
AND t0.X_10 = t1.X_10
AND t0.X_20 = t1.X_20
AND t0.P2_10 = t1.P2_10
)
OR (
1
AND t0.P1_01 = t1.P1_01
AND t0.X_02 = t1.X_02
AND t0.X_10 = t1.X_10
AND t0.P2_01 = t1.P2_01
)
OR (
1
AND t0.P1_01 = t1.P1_01
AND t0.X_02 = t1.X_02
AND t0.X_01 = t1.X_01
AND t0.X_10 = t1.X_10
)
OR (
1
AND t0.X_02 = t1.X_02
AND t0.X_01 = t1.X_01
AND t0.X_10 = t1.X_10
AND t0.P2_01 = t1.P2_01
)
OR (
1
AND t0.P1_10 = t1.P1_10
AND t0.X_01 = t1.X_01
AND t0.X_20 = t1.X_20
AND t0.P2_10 = t1.P2_10
)
OR (
1
AND t0.P1_10 = t1.P1_10
AND t0.X_01 = t1.X_01
AND t0.X_20 = t1.X_20
)
OR (
1
AND t0.X_01 = t1.X_01
AND t0.X_20 = t1.X_20
AND t0.P2_10 = t1.P2_10
)
OR (
1
AND t0.X_02 = t1.X_02
AND t0.X_01 = t1.X_01
AND t0.X_10 = t1.X_10
)
OR (
1
AND t0.P1_01 = t1.P1_01
AND t0.X_01 = t1.X_01
AND t0.P2_01 = t1.P2_01
)
OR (
1
AND t0.X_01 = t1.X_01
AND t0.X_10 = t1.X_10
AND t0.X_20 = t1.X_20
)
OR (
1
AND t0.P1_10 = t1.P1_10
AND t0.X_10 = t1.X_10
AND t0.P2_10 = t1.P2_10
)
OR (
1
AND t0.X_01 = t1.X_01
AND t0.X_02 = t1.X_02
AND t0.X_03 = t1.X_03
)
OR (
1
AND t0.X_10 = t1.X_10
AND t0.X_20 = t1.X_20
AND t0.X_30 = t1.X_30
)
)
)
ORDER BY
t0.date ASC
LIMIT
5
Answer the question
In order to leave comments, you need to log in
SELECT
*
FROM
table_sql AS t0
INNER JOIN table_sql AS t1 ON (
t0.id <> t1.id
AND (
0
OR (
1
AND t0.P1_01 = t1.P1_01
AND t0.X_02 = t1.X_02
AND t0.X_01 = t1.X_01
AND t0.X_10 = t1.X_10
AND t0.P2_01 = t1.P2_01
)
OR (
1
AND t0.P1_01 = t1.P1_01
AND t0.X_02 = t1.X_02
AND t0.X_01 = t1.X_01
AND t0.X_10 = t1.X_10
AND t0.X_02 = t1.X_02
AND t0.X_01 = t1.X_01
AND t0.X_10 = t1.X_10
AND t0.P2_01 = t1.P2_01
)
)
)
ORDER BY
t0.date ASC
LIMIT
5
SELECT
*
FROM
table_sql AS t0
INNER JOIN table_sql AS t1 ON
t0.id <> t1.id
AND t0.X_02 = t1.X_02
AND t0.X_01 = t1.X_01
AND t0.X_10 = t1.X_10
AND ( t0.P1_01 = t1.P1_01 OR t0.P2_01 = t1.P2_01)
ORDER BY
t0.date ASC
LIMIT
5
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question