douyouzheng2209 2018-01-31 19:12
浏览 50
已采纳

什么是多数据存储和提取的最佳方法?

The following table each owner has his own page, When someone visits it, All the Seats with SecretCodes appears

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.

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

$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?

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.

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 usingGROUP_CONCAT(), So I wonder which one is better for performance to be used.

[OSid - Seat  - SecretCode                            ]
[1    - Mark  - v2ttvgwrxt5cg36g3c63g36c3c54c26y4e73c6]
~48                                                   ]
[1    - Max   - c4wghwh65qcg45g5qx3                   ]
[2    - Jerry - 36vyh36cyh6y6wc363v636vc3yc6y3v7y37   ]
~48                                                   ]
[2    - Marco - h7wv5cg6qg6qcgqx3xgf5qwy4h            ]
[3    - Sonia - c3m73uhyv73vyhu3h33c65g33c7v373v73v7  ]
~48                                                   ]
[3    - John  - 5ctev5hmkbjev7h7kje                   ]
  • 写回答

1条回答 默认 最新

  • doulou0882 2018-02-02 12:18
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?