[英]What is the Best method for multiple Data Storing and Fetching?
The following table each owner
has his own page, When someone visits it, All the Seats
with SecretCodes
appears 下表中的每个owner
都有自己的页面,当有人访问它时,将显示带有SecretCodes
“所有Seats
”
OwnersSeats
[id - ownderid - type - Seat1 - SecretCode2 -> Seat50 - SecretCode50 ]
[1 - 3 - Premium - Mark - v2ttvgwrxt5cg36g3c63g36c3c54c26y4e73c6 -> Max - c4wghwh65qcg45g5qx3 ]
[2 - 3 - Standard - Jerry - 36vyh36cyh6y6wc363v636vc3yc6y3v7y37 -> Marco - h7wv5cg6qg6qcgqx3xgf5qwy4h]
[3 - 7 - Enterprise - Sonia - c3m73uhyv73vyhu3h33c65g33c7v373v73v7 -> John - 5ctev5hmkbjev7h7kje ]
With each Seat* VARCHAR(24), SecretCode* TEXT
Can be VARCHAR(512) instead.
对于每个Seat* VARCHAR(24), SecretCode* TEXT
Can be VARCHAR(512) instead.
Then I select them using this Query 然后我使用此查询选择它们
SELECT ownderid, type, Seat1, SecreCode2 -> 50 FROM seats WHERE ownerid = :ownerid
What is the best way to handle this to be Efficient, Well preformed and Easier to Use and Edit? 如何做到最好,高效且易于使用和编辑的最佳方法是什么?
I thought about storing all the seats in array inside the table as a TEXT
like this 我想到了存储在表中的数组中的所有的席位作为一个TEXT
这样
$SS = [
s1 => 'Mark', sc1 => 'v2ttvgwrxt5cg36g3c63g36c3c54c26y4e73c6',
s2 => '~~', sc2 => '~~~~~~~',
s3 => '~~', sc3 => '~~~~~~~',
s4 => '~~', sc4 => '~~~~~~~', -> 50
];
But i don't know if that Good or Bad for Performance. 但是我不知道这对性能好还是不好。
I want to limit
it to 50
, So i have 100 column[SS]
50 Seats
50 SecretCode
, Do I use normalization
to handle this? 我想将其limit
为50
,所以我有100 column[SS]
50 Seats
50 SecretCode
,我可以使用normalization
来处理吗?
I thought it would be better to put all the SS
in a Single row to be fetched all at once with all the ownerid
data, Since i suppose it would be faster. 我认为最好将所有SS
放在一个单独的行中,以便与所有ownerid
数据一次全部读取,因为我想这样会更快。
Also I don't know how can i fetch all the SS
from a normalized table
without using second query
to fetch all the releated data from it or using GROUP_CONCAT()
, So I wonder which one is better for performance to be used. 我也不知道如何从normalized table
获取所有SS
,而无需使用second query
从normalized table
中获取所有相关数据或使用GROUP_CONCAT()
,所以我想知道哪种性能更好。
[OSid - Seat - SecretCode ]
[1 - Mark - v2ttvgwrxt5cg36g3c63g36c3c54c26y4e73c6]
~48 ]
[1 - Max - c4wghwh65qcg45g5qx3 ]
[2 - Jerry - 36vyh36cyh6y6wc363v636vc3yc6y3v7y37 ]
~48 ]
[2 - Marco - h7wv5cg6qg6qcgqx3xgf5qwy4h ]
[3 - Sonia - c3m73uhyv73vyhu3h33c65g33c7v373v73v7 ]
~48 ]
[3 - John - 5ctev5hmkbjev7h7kje ]
I'm using an answer, not a comment, because a comment is quite restricted. 我使用的是答案,而不是评论,因为评论非常有限。 I think I start to understand your table. 我想我开始了解你的桌子了。 So I would rewrite the table with only these columns: 所以我只用这些列重写表:
id
ownderId
type
seat
secretCode
Data would look like this: 数据如下所示:
[id - ownderId - type - seat - secretCode ]
[1 - 3 - Premium - Mark - v2ttvgwrxt5cg36g3c63g36c3c54c26y4e73c6 ]
[2 - 3 - Standard - Jerry - 36vyh36cyh6y6wc363v636vc3yc6y3v7y37 ]
[3 - 7 - Enterprise - Sonia - c3m73uhyv73vyhu3h33c65g33c7v373v73v7 ]
[4 - 3 - Premium - Max - c4wghwh65qcg45g5qx3 ]
[5 - 3 - Standard - Marco - h7wv5cg6qg6qcgqx3xgf5qwy4h ]
[6 - 7 - Enterprise - John - 5ctev5hmkbjev7h7kje ]
If seat numbers are important to you, you could add a column with that number in it. 如果座位号对您很重要,则可以在其中添加一列。 Like this: 像这样:
[id - ownderId - type - seatNo - seat - secretCode ]
[1 - 3 - Premium - 1 - Mark - v2ttvgwrxt5cg36g3c63g36c3c54c26y4e73c6 ]
[2 - 3 - Standard - 1 - Jerry - 36vyh36cyh6y6wc363v636vc3yc6y3v7y37 ]
[3 - 7 - Enterprise - 1 - Sonia - c3m73uhyv73vyhu3h33c65g33c7v373v73v7 ]
[4 - 3 - Premium - 50 - Max - c4wghwh65qcg45g5qx3 ]
[5 - 3 - Standard - 50 - Marco - h7wv5cg6qg6qcgqx3xgf5qwy4h ]
[6 - 7 - Enterprise - 50 - John - 5ctev5hmkbjev7h7kje ]
The table is now normalized. 该表现在已标准化。 The same type of data is not present in multiple columns anymore. 多个列中不再存在相同类型的数据。 This would make your query look like this: 这将使您的查询看起来像这样:
SELECT seatNo, seat, secreCode FROM seats WHERE ownerId = :ownerid
Any other query on the data would be similar. 对数据的任何其他查询将是相似的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.