简体   繁体   English

MySQL获取所有行与按需选择

[英]mysql fetch all rows vs on demand select

im building an app in laravel (not relavant to this query i dont think). 我在laravel中构建一个应用程序(我不认为与该查询无关)。

there are a few user provided settings saved in a db table "settings". 在数据库表“设置”中保存了一些用户提供的设置。

for ease of use these values are being merged into the default config for the app (a simple php array) on boot, meaning i can just use 1 interface for accessing the values be they from the default config array, or overwritten by values in the db. 为了便于使用,这些值在启动时被合并到应用程序的默认配置(一个简单的php数组)中,这意味着我只能使用1个接口来访问这些值,这些值可以是默认配置数组中的值,也可以被D b。

This currently means a SELECT key,value FROM settings; 当前SELECT key,value FROM settings;这意味着一个SELECT key,value FROM settings; query is being used on boot before anything else. 在启动之前先使用查询。

im just wondering if anybody knows if this is sub optimal? 我只是想知道是否有人知道这是否次优?

I dont anticipate more than 100 or so rows in this table, with around 60% ish being needed on every request. 我预计此表中不会有100多个左右的行,每个请求大约需要60%的行。

Considering connection/lookup/return of a query would it be optimal to: 考虑连接/查找/查询返回将是最佳的:

  1. leave it as is and simply load all on boot 保持原样,只需在启动时加载所有内容

  2. add a autoload column and only load settings with this true on boot and load the rest "on demand" (when there requested) 添加一个autoload列,并仅在启动时加载此设置为true的设置,并“按需”加载其余设置(当有要求时)

  3. load every one "on demand" 每个“按需”加载

as there are so few rows, and the data is two simple strings per row im guesssing just loading them all is overall as fast as loading a few and then the rest on demand which involves multiple connection requests. 因为行太少,并且数据是每行两个简单的字符串,所以我猜只是将它们全部加载的速度总体上快于加载几行,然后按需加载其余部分,这涉及多个连接请求。

Am i right or should i consider optimising via option 2/3 or another method? 我是对的还是应该考虑通过选项2/3或其他方法进行优化?

For simplicity (less complicated code), I would just load them all. 为了简单起见(不那么复杂的代码),我将全部加载它们。 So what if 40%-ish aren't going to be needed for a particular request. 因此,如果特定请求不需要40%ish怎么办。

It's a simple SQL statement. 这是一个简单的SQL语句。 There aren't other variations of it (with different WHERE clauses) that need to be tested. 它没有其他变化(带有不同的WHERE子句)需要测试。

Overall, seems like it would be less code to test. 总体而言,似乎要测试的代码更少。 I don't see the potential savings of the other alternatives. 我看不到其他替代方案的潜在节省。 I can't justify the additional complexity. 我无法证明额外的复杂性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM