php - Is LEFT JOINING two tables with no reference to each other ON string conditions a bad idea? -


i'm migrating database between 2 systems using php , mysql.

in old 1 have 3 tables of interest:

t1
id (int)
...

t2
id (int)
t1_id (int)
d (string)
...

t3
id (int)
t1_id (int)
ds (string)
e (int)
...

in new 1 have t1 , t2

t2.d can have e.g. "abc" or "def" t3.ds can have "abc" or "def" or "abc, def"

i have created following query:

select     t2...,     t3.e t2 left join t3     on t2.id = t3.id     , t3.ds concat("%", t2.d, "%") t2.id = ? 

the query work, worried performance of join when have lots of entries (to migrate iterate on each of entries t1, each having multiple entries in t2 , t3).

so @ bottom, go question - worth join them or should use different approach, separate query or data manipulation on php level?

here's mysql explain if that's relevant (unfortunately doesn't mean me, appreciate help):

id | select_type | table | type | possible_keys        | key           | key_len | ref                    | rows  | 1  | simple      | modi  | ref  | primary,order_number | order_number  | 4       | const                  | 3     | using temporary; using filesort 1  | simple      | ai    | ref  | detail_number        | detail_number | 4       | max.modi.detail_number | 1     | null 1  | simple      | edi   |  | null                 | null          | null    | null                   | 26389 | using where; using join buffer (block nested loop) 

this long comment.

if concerned performance, not store lists in string. should have junction table, 1 row per element of list. in other words, 'abc, def' no-no. table 2 rows, 1 'abc' , 'def' way go.

because have data structure not optimized sql, there little can performance perspective. like can do.


Comments