私はデータベースデザインではあまりよく動かないので、皆さんに助けを求めてきました。私はユーザーの記録を持つテーブルを持っています。タブレットはこのようなものです:
+----------+----------+----------+----------+----------+----------+----------+---------
| id | username | password | firstName| lastName | birthDate| pictures| .....
+----------+----------+----------+----------+----------+----------+----------+---------
| . | . | . | . | . | . | . |
| . | . | . | . | . | . | . | .....
. . . . . . .
The pictures field indicates how many pictures a user has
uploaded.
I have written a feature that allows users to upload pictures to
our servers. The file uploaded is named to something random. Users
are only allowed 6 images.
I am currently getting the location of the file and storing the
locations in a table that looks like this:
+----------+----------+----------+----------+----------+----------+----------+---------
| id | username | default | pic1 | pic2 | pic3 | pic4 | .....
+----------+----------+----------+----------+----------+----------+----------+---------
| . | . | . | . | . | . | . |
| . | . | . | . | . | . | . | .....
. . . . . . .
ユーザが0ピクチャ以上を有すると仮定すると、ユーザプロファイルが訪問されると、「デフォルト」フィールドが呼び出され、デフォルトピクチャのアドレスがどのカラムに格納されるかを取得する。たとえば、
‘default’が2の場合、列
‘pic2’のデータがプルされて最初に返され、次に空でない他の列がそれぞれのデータを返します。
My first question is: is this method of having multiple tables a
bad idea? Is implementing a design where a picture has its own
column a bad idea?
As you guys can see this method is not scaleable in the least bit.
What would be a good, efficient, scaleable design to
implement this profile system? I am expecting to have 50,000 –
60,000 users.
Also if possible recommend me a good book that will give me a crash
course in database design! (crash course please nothing too long or
detailed!)
なぜこのデザインが必要なのか(非常に疑わしい)非常に具体的な理由がない限り、あなたは次のようなものを持っていくべきだと思います:
users:
- id
- username
- email
- ...
pictures
- id
- user_id
- default (or order)
- picture_location
これは、あなたがuser_idにインデックスを持っていることを前提としています。また、ユーザーごとの最大画像数を簡単に変更できます。もちろん、制限はアプリケーションによって強制されます。