简体   繁体   English

数据库中存储多个主键; sql vs nosql

[英]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.

相关问题 SQL数据库列中的数组 - 或 - 一个键/值noSQL存储? - Array in a SQL database column -or- One key/value noSQL store? 主键搜索有多个结果 - More than one result on Primary Key search SQL查询,用于选择具有多个指向主键表的链接的外键行 - SQL query for selecting foreign-key rows with more than one link to the primary-key table 数据库设计:复合键与一列主键 - Database Design: Composite key vs one column primary key MySQL外键使用多个字段来引用另一张表中的主键 - MySQL foreign key using more than one field to reference to a primary key from another table 我可以有一个主键表,它是多个表中的外键吗 - Can I have a Table with primary Key which is a Foreign Key in more than one Table MySQL-如何选择主键多次出现并且至少另一个字段匹配的行? - MySQL - how to select rows where a primary key occurs more than once AND at least one of another field matches? 我通过主键查询的mysql语句有时返回多行,那么发生了什么? - My mysql statement to query by primary key sometimes returns more than one row, so what happened? 有没有一种方法可以在SQL数据库的字段中插入多个数据? - Is there a way to insert more than one data in a field in SQL database? 我们能否在数据库中存储仅对应一个主键/序列ID的多个数据条目? - can we store multiple data entries in database corresponding only one primary key/sequence id?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM