[英]Database to store more than one primary key; sql vs nosql
I'm developing an app that needs a database with more than one primary key. 我正在开发一个需要一个具有多个主键的数据库的应用程序。 Its architecture would consist in something like that:
它的体系结构将包含以下内容:
PK == Primary Key
| column1 | column2(PK) | columns3(PK) | column4(PK) | column5(PK)
---------------------------------------------------------------------------
row1 | word | string | string | string | string
---------------------------------------------------------------------------
row2 | word | string | string | string | string
---------------------------------------------------------------------------
row3 | word | string | string | string | string
---------------------------------------------------------------------------
row4 | word | string | string | string | string
---------------------------------------------------------------------------
row5 | word | string | string | string | string
---------------------------------------------------------------------------
rowN | word | string | string | string | string
The app will ask the database for the Word (in column1) that correspond to the string specified. 该应用程序将向数据库询问与指定字符串相对应的Word(在column1中)。 The query would be something like that:
该查询将是这样的:
SELECT word
FROM table
WHERE columnN = 'string'
LIMIT 1;
where word
is the word on column1, columnN
is the column 1,2,3,4 or 5 and string
is a string that could be contained on columnN
其中
word
是column1上的单词, columnN
是1,2,3,4或5列, string
是可以包含在columnN
上的columnN
The database will contain million of rows so that I need more that one primary key in order to get the word
that correspond to the string very fast. 数据库将包含数百万行,因此我需要一个以上的主键才能非常快速地获得与字符串相对应的
word
。
I've created a database with this structure (but only one primary key on column2
) and 3,000,000 rows. 我已经创建了一个具有这种结构(但
column2
上只有一个主键)和3,000,000行的数据库。 When I search the word that correspond to the string contained on the column with the primary key, the DB responds me in less than half-second but if I search a word that correspond to a string contained on a column without primary key, the DB responds me on more than half-hour (unacceptable) 当我使用主键搜索与包含在列中的字符串相对应的单词时,DB会在不到半秒的时间内响应我,但是如果我搜索与没有主键的包含在列中的字符串相对应的单词,则DB半小时以上答复我(不可接受)
So my question is: 所以我的问题是:
How should I structure the database in order to get the response fast independently of the column that contains the string? 我应该如何构造数据库以便独立于包含字符串的列快速获得响应?
I've been reading about noSql databases but I don't know if that's what I need because the database I need is fully relational 我一直在阅读有关noSql数据库的信息,但我不知道这是否是我需要的,因为我需要的数据库是完全关系的
Edit: It must be free solution and I have to be able to run it on a domestic computer 编辑:它必须是免费的解决方案,我必须能够在家用计算机上运行
I think that adding too many primary keys is not your solution here. 我认为添加过多的主键不是您的解决方案。 Notice that normally primary keys have a size limitation, so you will bump into a road block sooner than later.
请注意,通常主键有大小限制,因此您迟早会遇到障碍。
What you might be needing here is either a non-clustered index or a vendor-specific technology such as Full-Text Search in MS SQL Server which creates (IMO and by experience) very efficient indexes 您在这里可能需要的是非聚集索引或特定于供应商的技术,例如MS SQL Server中的全文本搜索,该技术可以创建(IMO和经验丰富的)高效索引
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.