简体   繁体   English

只有一个索引的数据库表...坏主意?

[英]Database tables with only one index … bad idea?

If a programming language allowed the creation of database tables, but only allowed one field to be used as an index ... how limiting would that be? 如果一种编程语言允许创建数据库表,但只允许一个字段用作索引......那将是多少限制? I am not a real database programmer, so I'm wondering if such a system could be used as the basis for serious databases, or would be only a toy. 我不是一个真正的数据库程序员,所以我想知道这样的系统是否可以用作严肃数据库的基础,或者只是一个玩具。

That would be extremely limiting. 这将是非常有限的。 I've seen as many as 11 indexes on tables I've dealt with, all of them having a purpose. 我在桌子上看过多达11个索引,所有这些索引都有目的。 No doubt there are cases out there with substantially more. 毫无疑问,有些案件的情况要多得多。

At a minimum in a database the primary key and all foreign keys will be (or should be) indexed. 至少在数据库中,主键和所有外键将被(或应该)索引。

Also it's common for indexes to span multiple columns. 索引跨越多列也很常见。

Non-relational databases (currently all the rage with the NoSQL movement) approximate such a situation. 非关系数据库(目前在NoSQL运动中风靡一时)近似于这种情况。 Many such databases are anything but toys, and are intensely used as the basis of hugely scalable production systems -- the lack of free indexing and other limitations empower almost unbelievable scalability, especially for "mostly-read" scenarios. 许多这样的数据库都不是玩具,而是被大量使用作为可扩展的生产系统的基础 - 缺乏自由索引和其他限制几乎令人难以置信的可扩展性,特别是对于“大多数读取”场景。 The downside is basically in having to give up normalization, and duplicating information all over the place in ways that are strictly dependent on what queries need what degree of optimization. 缺点主要在于必须放弃规范化,并以严格依赖于查询需要什么程度的优化的方式在整个地方复制信息。

I'm not sure what your "single index" scenario is based on, but unless it offers the same kinds of advantages as the best "nosql" storage systems (and you're willing to fully pay the price for that), it seems unlikely to be a technically viable concept;-). 我不确定你的“单一索引”场景是基于什么,但除非它提供与最好的“nosql”存储系统相同的优势(并且你愿意为此付出全部代价),似乎不太可能是技术上可行的概念;-)。

It depends. 这取决于。 Berkeley DB eg only has a single key and is very useful for its purposes. Berkeley DB例如只有一个密钥,对于它的用途非常有用。

A relational DB on the other hand should give you the opportunity to define as many indices as you like (as cletus mentioned, foreign key queries would suffer from very poor performance otherwise) 另一方面,关系数据库应该让你有机会定义任意数量的索引(正如cletus所提到的,外键查询将遭受非常糟糕的性能,否则)

Generally: an index is for speeding up database lookup: like in a book, you search the word "computer", you browse the (alphabetical!) index, and find all page-numbers. 通常:索引用于加速数据库查找:如在书中,您搜索单词“computer”,浏览(按字母顺序排列!)索引,并查找所有页码。

If (very hypothetical reasoning) one creates a database which optimized lookup times without using indices: then such a database containing only one index is not a bad idea. 如果(非常假设的推理)创建了一个数据库,该数据库在不使用索引的情况下优化了查找时间:那么这样一个只包含一个索引的数据库并不是一个坏主意。

But if you're talking about a mainstream DB, then I'd say: depends on the content. 但如果你在谈论主流数据库,那么我会说:取决于内容。

It depends on what you are going to do with the data. 这取决于您将如何处理数据。

If you search and select based on an unindexed field, the process is going to be slow. 如果您根据未编制索引的字段进行搜索和选择,则该过程将变慢。 Likewise, if you perform join or merge operations based on an unindexed field, you get a slow down. 同样,如果您根据未编制索引的字段执行连接或合并操作,则速度会变慢。

If the table has millions of rows, this could be too slow to be acceptable. 如果表有数百万行,这可能太慢而无法接受。

Limiting yourself to access by way of just one field can in certain situations be too limiting. 在某些情况下限制自己仅通过一个字段进行访问可能会限制太多。

Again, it depends on what you are going to do with the data. 同样,这取决于您将如何处理数据。

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

相关问题 将所有表放入一个数据库 - 好或坏 - Placing all tables into one database - Good or Bad 将一个更大的数据库表分成更多表是个好主意吗 - Is it a good idea to break one bigger database table into more tables 使用SQLite作为生产数据库,但不好的想法 - Using SQLite as production database, bad idea but 将javascript和css存储在数据库中是一个坏主意吗? - Is it a bad idea to store javascript and css in a database? 具有“开放架构”的数据库 - 好主意还是坏主意? - Database with “Open Schema” - Good or Bad Idea? 拆分数据库Web应用程序-好主意还是坏主意? - split a database web application - good idea or bad idea? 不在此数据库中使用规范化表是不是很糟糕? - Is it bad to not use normalised tables in this database? 将数据库数据拆分为多个表而不是将所有内容存储在 PostgreSQL 的一个表中是否是个好主意? - Will it be a good idea to split database data into multiple tables instead of storing everything in one table for PostgreSQL? 在上传新内容时动态生成SQL表-一个坏主意? - Generating SQL Tables on the fly as new content is uploaded - A bad idea? 在插入数据库而不是输出之前逃避HTML是一个坏主意吗? - Is it a bad idea to escape HTML before inserting into a database instead of upon output?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM