-
-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Partial Indexes [CORE3384] #3750
Comments
Modified by: Vladimir Arkhipov (arkinform)description: Example: CREATE UNIQUE INDEX orders_number_idx ON orders (number) Description from http://www.postgresql.org/docs/8.0/static/indexes-partial.html: "A partial index is an index built over a subset of a table; the subset is defined by a conditional expression (called the predicate of the partial index). The index contains entries for only those table rows that satisfy the predicate." "A major motivation for partial indexes is to avoid indexing common values. Since a query searching for a common value (one that accounts for more than a few percent of all the table rows) will not use the index anyway, there is no point in keeping those rows in the index at all. This reduces the size of the index, which will speed up queries that do use the index. It will also speed up many table update operations because the index does not need to be updated in all cases." Very very useful !!! => Example: CREATE UNIQUE INDEX orders_number_idx ON orders (number) Description from http://www.postgresql.org/docs/8.0/static/indexes-partial.html "A partial index is an index built over a subset of a table; the subset is defined by a conditional expression (called the predicate of the partial index). The index contains entries for only those table rows that satisfy the predicate." "A major motivation for partial indexes is to avoid indexing common values. Since a query searching for a common value (one that accounts for more than a few percent of all the table rows) will not use the index anyway, there is no point in keeping those rows in the index at all. This reduces the size of the index, which will speed up queries that do use the index. It will also speed up many table update operations because the index does not need to be updated in all cases." Very very useful !!! |
Commented by: @ibaseru Have doubts about this feature since it was implemented in FoxPro. Less space used by index - yes and good. Speedup queries? No. The amount of index pages being read will not be much less than in ordinary index. Histograms are better, mostly knowing that data may change, and such partial index must be rebuilt with new condition to be used in new conditions. Well, maybe I'm wrong, but I'd like to see more theoretical examples (close to practics) with benefits of indices like this. Examples from PostgreSQL looks too childish. |
Commented by: Ann Harrison (awharrison) Firebird differs from Postgres in a couple of ways that affect this The other is that Firebird does not keep multiple index entries for |
Commented by: Dirk Rothe (drothe) Real World: In query-plans for the the "Field is Null" case, the index of this Field is choosen (because of a higher selectivity) before other "better indexes". We work around this problem by trying to remember to disable the index with "Field+0 is Null" in these cases. This speeds up these queries by some order of magnitude. But from time to time somebody forgets this "trick" - so I would really like to fix this problem by excluding some Values from the Index. |
Commented by: @dyemanov Dirk, in this case a value distribution histogram is your friend, as with its existence the optimizer will not use an index for FIELD IS NULL while still be using an index for equality comparisons. |
Commented by: Vladimir Arkhipov (arkinform) I see 2 applications of partial indexes: 1. Restrict unique values for not null fields. For example, number of case history for patient in medicine. The number may be not exist yet. But not null number must be unique. I don't know how to do it "gracefully" without partial indexes. CREATE UNIQUE INDEX patients_histnum_idx ON patients (histnum) 2. Large tables with fields where the most of values is null. Patient attribute, for example, allergy (or something like that) where 3-5% of values filled. We never need to find patients without allergy, but we often need to know about the presence of allergy for patients. I understand that Firebird store indexes very compact, but it is still unnecessary time and disk space. P.S. What about speed of garbage collection for indexes where 99% of values is null? Is it problem or no? |
Commented by: @dyemanov As for your case (1), I'm not sure I get it. Firebird allows you to have any number of NULLs inside a uniquely constrained column. What is the problem? |
Commented by: Vladimir Arkhipov (arkinform) Unfortunately I did not know about this feature. Thank you :) |
Commented by: Vladimir Arkhipov (arkinform) What about case (2) and speed of garbage collection? Does this affect garbage collection in principle? |
Commented by: Dirk Rothe (drothe) Are "value distribution histograms" an expected 3.0 feature? I haven't that found that much information by googling for it. |
Commented by: Dirk Rothe (drothe) Dmitry: Very nice, and a big thank you to all involved! |
Commented by: Sean Leyne (seanleyne) My reading of this case is that this issue can be closed, since there is no new action/change which is required. Correct? |
Commented by: @dyemanov I'm not sure. Some benefits of this feature still exist, the question is primarily whether they justify the development cost. But regardless, the priority should be decreased to "minor". |
Commented by: @livius2 If you still need real world sample: table REPORT with column STATE (something like Firebird Tracker) values of state: and you then can create partial index: CREATE INDEX IXAP_REPORTS_STATE ON REPORT (STATE) this index is small and is used by common queries |
Commented by: @livius2 If this feature will be done Example ----------------------------------------------------- ----------------------------------------------------- CRATE TABLE NOTES , ID_CUSTOMER BIGINT NOT NULL ,REF_TYPE INTEGER NOT NULL ----------------------------------------------------- ALTER TABLE NOTES ADD CONSTRAINT FK_NOTES__CUSTOMER FOREIGN KEY(ID_REF) WHERE REF_TYPE=1 REFERENCES CUSTOMER(ID) ON DELETE NO ACTION ON UPDATE CASCADE; This is maybe not ideal design - but sometimes this will simplify many problems |
+1 if this feature can be done. Not for performance but for unique enforcement. For example, consider the table:
Basically a table which needs to track changes over time of a value (can be anything like an medical record number, etc.) but basically the business requirement is: value must be unique if it is active. In PostgreSQL, Oracle, and even SQLite this is done via:
i.e. Enforce the unique constraint on If there is a way to do this other than indexes in Firebird I'd love an example - currently we've just removed unique checking on this value when users use Firebird, it would be nice if our Firebird provider could behave the same way as our Postgres, SQLite and Oracle providers :) |
You may use expression index right now:
|
QA: see tests for #7257 |
Submitted by: Vladimir Arkhipov (arkinform)
Votes: 4
Example:
CREATE UNIQUE INDEX orders_number_idx ON orders (number)
WHERE number is not null
Description from http://www.postgresql.org/docs/8.0/static/indexes-partial.html
"A partial index is an index built over a subset of a table; the subset is defined by a conditional expression (called the predicate of the partial index). The index contains entries for only those table rows that satisfy the predicate."
"A major motivation for partial indexes is to avoid indexing common values. Since a query searching for a common value (one that accounts for more than a few percent of all the table rows) will not use the index anyway, there is no point in keeping those rows in the index at all. This reduces the size of the index, which will speed up queries that do use the index. It will also speed up many table update operations because the index does not need to be updated in all cases."
Very very useful !!!
The text was updated successfully, but these errors were encountered: