English 中文(简体)
指数化只影响WHERE条款?
原标题:Indexing affects only the WHERE clause?

如果我有这样的情况:

CREATE INDEX   idx_myTable_field_x
ON             myTable
USING          btree (field_x);

SELECT COUNT(field_x), field_x FROM myTable GROUP BY field_x ORDER BY field_x;

Imagine myTable with around 500,000 rows and most of field_x 价值观是独特的。

由于我没有使用任何<代码>。 WHERE Articles, will be found index have any effect at all in my query?

Edit: I m asking this question because I don t get any relevant difference between query-times before and after creating the index; They always take about 8 seconds (which, of course is too much time!). Is this behaviour expected?

最佳回答

该指数将无助于这里,因为你正在读整个表格,但在达到指数一时没有使用(PostgreSQL还没有指数化扫描)。

由于指数中几乎所有的数值都是独一无二的,因此,在这种局势中确实不会有任何帮助。 指数调查(包括其他房舍管理处的指数调查)往往真正有助于研究少数几行。

可能使用该指数进行排序的可能性很小,但我怀疑这一点。

请看<代码>的产出 EXPLAIN ANALYZE VERBOSE,你可以看到,这种分类是记忆中进行的,还是(由于结果的规模)在磁盘上进行的。

如果在磁盘上进行分类,你可以加快处理速度,增加工作——无论是在全球还是仅仅在本届会议上。

问题回答

由于field_x是你询问中参考的唯一栏目,您的索引s 。 问询和帮助您避免对<条码>可读的实际浏览量。

www.un.org/Depts/DGACM/index_spanish.htm 如下文的评论讨论所示,虽然这一答案对大多数房舍管理事务实施都有效,但不适用于邮资。

该指数应当使用。 如果你想看到如何使用(或不使用)你的指数,那么问询的执行计划就是一个很大的地方,可以看到数据库决定做些什么。 在你看来,你应当执行这样的行动:

explain SELECT COUNT(field_x), field_x FROM myTable GROUP BY field_x ORDER BY field_x;

详情见:www.postgresql.org/docs/8.4/static/sql-explain.html。

http://wiki.postgresql.org/wiki/Image:Explaining_EXPLAIN.pdf”rel=“nofollow” http://wiki.postgresql.org/wiki/Image:Explaining_EXPLAIN.pdf。 这更深入。





相关问题
摘录数据

我如何将Excel板的数据输入我的Django应用? I m将PosgreSQL数据库作为数据库。

Postgres dump of only parts of tables for a dev snapshot

On production our database is a few hundred gigabytes in size. For development and testing, we need to create snapshots of this database that are functionally equivalent, but which are only 10 or 20 ...

How to join attributes in sql select statement?

I want to join few attributes in select statement as one for example select id, (name + + surname + + age) as info from users this doesn t work, how to do it? I m using postgreSQL.

What text encoding to use?

I need to setup my PostgreSQL DB s text encoding to handle non-American English characters that you d find showing up in languages such as German, Spanish, and French. What character encoding should ...

SQL LIKE condition to check for integer?

I am using a set of SQL LIKE conditions to go through the alphabet and list all items beginning with the appropriate letter, e.g. to get all books where the title starts with the letter "A": SELECT * ...

热门标签