Indexing only affects WHERE clause?

If I have something like:

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 myTablearound 500,000 rowsand most of the values field_xare unique.

Since I am not using any suggestion WHERE, will the created index even have any effect in my query?

Change . I ask this question because I do not get the difference between the queries before and after creating the index; They always take about 8 seconds (which, of course, is too much time!). Is this behavior expected?

+3
source share
3 answers

, , (PostgreSQL )

, . ( ), , .

, , .

EXPLAIN ANALYZE VERBOSE, , (- ) .

, , work_mem - , .

+6

field_x - , , myTable.

EDIT. , , postgresql.

+3

. - , ( ), - , , . - :

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

, , , postgres: http://www.postgresql.org/docs/8.4/static/sql-explain.html

: http://wiki.postgresql.org/wiki/Image:Explaining_EXPLAIN.pdf, .

+2

Source: https://habr.com/ru/post/1783694/


All Articles