About php business logic, mysql optimization problem

there is a usr table containing uid,username
business table 1, the information stored are fields uid,username
business table 2, and only uid,
(multiple data in business table 2 corresponds to one data in business table 1)

the environmental background of the problem and the method you try

existing: query traverses business table 2, the data is an array of list, you also need to assemble username, on list to display
method one is to query username;
according to each list to database usr table according to uid, the second is to first traverse query business table 1, use an empty array arr,key to store username, corresponding to value username, to traverse list, use array_key_exists to determine whether uid is one of the keys of arr, and if so, get arr [uid] as username

questions

The second advantage of the

method is that it avoids multiple database queries of username, but there are doubts about using the key of an empty array to store uid,. If the uid value is very large, such as 10000, will this involve the memory problem of the php array (I don"t know much about this)
I also want to know if method 2 has any other shortcomings, and if so, is there any other better processing method

?
join


of


Database join


it is not difficult to understand the use of multiple tables, or to directly understand the use of multiple tables. This problem is not difficult, and it is a common requirement in business.


select t2.uid as t2uid,t1.uid as t1uid,t1.username from table2 as t2 join table1 as t1 on t2.uid = t1.uid
,

either use join on, or left join on directly, or you can try the in () method of mysql

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1c2a76e-339e2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1c2a76e-339e2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?