什么是更好的 - 一个字段或八个 - mysql位测试 [英] what is better - one field or eight - mysql bit testing

查看:44
本文介绍了什么是更好的 - 一个字段或八个 - mysql位测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Folk


我必须在我的数据库中存储多达8个布尔位的信息



例如


[]与餐厅

[]直通设施

[]黄色窗户

[] wifi factilities

等...


有三种方法可以将这些信息存储在我的mysql数据库中

A.添加八个字段(小整数)

B.添加一个小整数并在PHP中创建一个可以翻译的函数

存储到八个中的数字布尔值(位)

C.创建一个表格列表

ItemID

相关特征

在C中,你只会列出列出的项目

的真实特征。

选项B在MySql中是最有效的,但你会推荐它吗?创建PHP网站时,
。问题是用户需要

用漂亮的网页等输入它们......


你认为什么。


TIA


- Nicolaaas

解决方案

" windandwaves" < NF ******* @ gmail.com>在消息中写道

新闻:11 ********************** @ j73g2000cwa.googlegr oups.com ...

我必须在我的数据库中存储多达八个布尔位的信息。
有三种方法可以将这些信息存储在我的mysql数据库中。
A.添加八个字段(微小整数)
B.添加一个小整数并在PHP中创建一个函数,可以将存储的数字转换成8个布尔值(位)
C.创建一个表格list
ItemID
相关特征
在C中,您只列出列出的项目的真实特征。

选项B是最多的在MySql中有效,但是在创建PHP网站时你会推荐它吗?问题是用户需要用漂亮的网页等输入它们......




你想知道这些选项中的哪一个是 ;最好的" ;?如果是这样,您需要

定义最佳。如果你定义最好,我怀疑你会回答

你自己的问题。


如果你只想要一些有用的东西,翻转一枚硬币。他们都工作。

在这种情况下你最大的挑战是找到一个3面硬币,

套餐。


我对项目的经验强烈表明,您目前的八个字段

将会增加。这似乎总是发生。所以你可能会考虑

这些方案中哪些是最容易增长的。注意,B表示B。是非常棘手的

因为它没有很好地扩展(你很快就用完了)。


另外,考虑一个更哲学的问题:为什么你要考虑将信息存储为位?
?我认为答案是因为它可能会这样做。如果你的八个特征不是布尔值会怎么样?

如果它们是三元素怎么办?在这种情况下,你可能不会将它们存储为位,即使三元数据确实存在,在最终分析中,总是将b / b
存储为位。问问自己,改变

存储方法是否有意义只是因为你的特殊特征是布尔值?


- Dana


在生命的岩石上刻上神秘的符文,

comp.lang.php的windandwaves的最后一句话简单明了:

我必须在我的数据库中存储多达八个关于项目的布尔位信息。

有三种方法可以将这些信息存储在我的mysql数据库中
A.添加八个字段(小整数)
B.添加一个小整数并在PHP中创建一个可以翻译的函数




我会选择B,只是个人喜好。


-

Alan Little

Phorm PHP表格处理器
http://www.phorm.com/


Alan Little写道:

Carv在生命的岩石上用神秘的符文编写,comp.lang.php的windandwaves的最后一句话简单明了:

我必须存储多达8个布尔位有关项目的信息
在我的数据库中。

有三种方法可以将这些信息存储在我的mysql数据库中
A.添加八个字段(小整数)
B添加一个小整数并在PHP中创建一个可以翻译的函数



我会选择B,只是我的个人偏好。



如果你试着为我工作,你会得到一口。


这是一个不好的主意。 SQL没有它的可见性。它没有正常化,而且它不会缩放。公平地说,某些类型的搜索可以非常快速地进行,但是它们不太可能特别常见。


C.


Hi Folk

I have to store up to eight boolean bits of information about an item
in my database.

e.g.

[ ] with restaurant
[ ] drive-through facility
[ ] yellow windows
[ ] wifi factilities
etc...

There are three ways of storing this information in my mysql database
A. add eight fields (tiny integer)
B. add one tiny integer and create a function in PHP that can translate
the number stored into a eight boolean values (the bits)
C. create a table which list
ItemID
Associated characteristics
In C, you will only list the characteristics that are true for the item
listed.

Option B is the most efficient in MySql, but would you recommend it
when creating a PHP website. The problem is that the user needs to
enter them with a nice webform, etc...

What do you reckon.

TIA

- Nicolaaas

解决方案

"windandwaves" <nf*******@gmail.com> wrote in message
news:11**********************@j73g2000cwa.googlegr oups.com...

I have to store up to eight boolean bits of information about an item
in my database.
There are three ways of storing this information in my mysql database
A. add eight fields (tiny integer)
B. add one tiny integer and create a function in PHP that can translate
the number stored into a eight boolean values (the bits)
C. create a table which list
ItemID
Associated characteristics
In C, you will only list the characteristics that are true for the item
listed.

Option B is the most efficient in MySql, but would you recommend it
when creating a PHP website. The problem is that the user needs to
enter them with a nice webform, etc...



Do you want to know which of these options is "best"? If so, you need to
define "best". And if you define "best", I suspect you''ll have answered
your own question.

If you simply want something that works, flip a coin. They all "work".
Your biggest challenge in this case would be to find a 3-sided coin, of
course.

My experience with projects suggests strongly that your current eight fields
will grow in number. This always seems to happen. So you might consider
which of these schemes is the easiest to grow. Note that "B" is tricky
because it doesn''t scale up very well (you run out of bits fairly quickly).

Also, consider a more philosophical question: why are you considering
storing the information as bits? I assume the answer is "because it''s
possible to do so". What if your eight characteristics were not boolean?
What if they were, say, ternary? In that case, you would probably not store
them as bits, even though ternary data does, in the final analysis, always
get stored as bits. Ask yourself whether it makes sense to change the
storage method just because your particular characteristics are boolean?

-- Dana


Carved in mystic runes upon the very living rock, the last words of
windandwaves of comp.lang.php make plain:

I have to store up to eight boolean bits of information about an item
in my database.

There are three ways of storing this information in my mysql database
A. add eight fields (tiny integer)
B. add one tiny integer and create a function in PHP that can translate



I''d go with B, just my personal preference.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/


Alan Little wrote:

Carved in mystic runes upon the very living rock, the last words of
windandwaves of comp.lang.php make plain:

I have to store up to eight boolean bits of information about an item
in my database.

There are three ways of storing this information in my mysql database
A. add eight fields (tiny integer)
B. add one tiny integer and create a function in PHP that can translate



I''d go with B, just my personal preference.



You''d get a mouthful if you tried that working for me.

Its a BAD idea. SQL has no visibility of it. It''s not normalized and it
doesn''t scale. In fairness certain types of search can be done very fast,
but they''re unlikely to be particularly common.

C.


这篇关于什么是更好的 - 一个字段或八个 - mysql位测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆