Pergunta

Sorry if this has been asked before, I couldn't think of how to formulate the question.

I have a database (specifically in amazon SimpleDB) in where I use 2 domains.

  • Domain 1 has a list of users with some general information.

  • Domain 2 is a list of items with the Item information.

I want to be able to query for all the items that belong to an specific user from domain 1. For this, each item can only belong to 1 user, so one of the attributes from domain 2 is, userID.

Until know I thought that the best option was to keep an attribute in domain 1 with the list of the items that this user has (something like item1&&item2&&item3&&...etc) and just query for this attribute. Which i think would make it very efficient, however i realized that the attribute limit is 1024 bytes so I will eventually run out of space (because my item names are a bit long).

In this case i thought I would have to do a "select * where userID = something" in Domain2 every time I want to get all the user items, but somehow this doesn't seem so efficient. (I could still keep a last updated and number of items in domain 1 to see if my local device needs to query or if it has the newest version locally).

Any advice would be great!

(Or should i ask this in stackoverflow for databases?)

Foi útil?

Solução

I don't know about amazon-simpledb, but in database terms, you have two tables: the first is a table of USERS which presumably stores at least a user id and username; the second is a table of ITEMS which stores an item id, an item name and its current owner/user.

You do NOT want to store a list of items that the user owns in a delimited list in the users table; traversing this list will be painful. Apart from that, the data (which users owns which items) already exists in the items table.

In standard SQL, you would write the following query to retrieve a list of the items that a specific user owns

select items.name
from items inner join users
on items.user = users.id
where users.username = 'Luis'

Standard databases are built to handle tables with millions of entries so don't worry about efficiency (at least, as long as you add the appropriate indexes - you would need an index on the 'user' field in the items table).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top