English 中文(简体)
Greenplum indexing not used on query
原标题:

I have created a table T , which has an index created on a column C (btree index) , but when i run the select query this index is not being used.

Ex:

Explain select * from T where C= xxx 

This searches in all the segments sequentially , without considering the index which i have created.

I have used the following flags

enable_seqscan = off
enable_bitmapscan = off
enable_indexscan = on

Am I missing anything?Kindly explain?

Thanks Ganesh.R

问题回答

It s possible that the query optimizer, for whatever reason, thinks that it s better not to use the index. Also, you may need to do an ANALYZE on the table if the statistical metadata is out of date. See this article (or others like it) for more detailed information.

w/o explain analyze it is quite hard to tell why, but few points:

  • GP use very high random_page_cost and seq_page_cost is 1. The default value for random_page_cost is 100 which completely discourages optimiser to use index scans
  • enable_seqscan = off doesn t turn off seq scan completely. seq scans are just heavily
    penalised
  • if table is small (100 - 10k records) it s might be faster to read it sequentially and ignore index at all

Unlike traditional RDBMSs, an index may not be the preferable way to access data in Greenplum.

Greenplum is tuned out of the box to prefer table scans over index scans, and you have to do a lot of tweaking to change that. You can set additional parameters to help the GP optimizer choose indexes including set enable_nestloop on, cpu_index_tuple_cost and others. Check Appendix D of the GP Admin guide for a full set of tunable parameters.

Also, how do you have the data distributed? That can play a part in how the optimizer is choosing to process your query.

If your table is partitioned, there is one more possible reason for your index not being used: Your table has an index, but some or all of your partitions do not. You can check this be looking at the system view pg_indexes. Are there entries for the partitions?

The root cause for this problem probably is that alter table TABLE add partition... does not automatically create the indexes that you have defined for TABLE.

There are two solutions:

  • create index INDEXNAME on PARTITIONTABLENAME(ROWLIST..) after adding a partition. Search the system view pg_partitions the get the PARTITIONTABLENAME! It s not the same as the PARTITIONNAME.
  • Delay create index on your table to the point where you have added all the partitions that you will need. That s because creating an index on a table automatically creates indices on all existing partitions.

By the way, dropping the index on the table does not drop the indexes on the partitions.

I m sorry I cannot give you any references to the GP Admin Guide as I m either blind or wrong or the Admin Guide ignores this matter completely.





相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签