mysql - What is more efficient(speed/memory): a join or multiple selects -


i have following tables:

users

userid|name

items

itemid|userid|description

what want achieve: want read database users , items (an user can have multiple items). data want stored in structure following:

user { id name array<item> } 

where item is

item { itemid userid description } 

my first option call select * users, partially fill array users , after each user select * items userid=wantedid , complete array of items.

is approach correct, or should use join this?

a reason don't want use join have lot of redundant data:

userid1|name1|itemid11|description11 userid1|name1|itemid12|description12 userid1|name1|itemid13|description13 userid1|name1|itemid14|description14 userid2|name2|itemid21|description21 userid2|name2|itemid22|description22 userid2|name2|itemid23|description23 userid2|name2|itemid24|description24 

by redundant mean: userid1,name1 , userid2,name2

is reason justified?

later edit: added title speed or memory when talking efficiency

you're trading off network roundtrips bytes on wire , in ram. network latency bigger problem, since memory cheap , networks have gotten faster. gets worse size of first result set grows - google "(n+1) query problem".

i'd prefer join. don't write using select *; that's bad idea in every case. should spell out precisely columns want.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -