Index podle funkce v PostgreSQL

Honza Pazdziora adelton na informatics.muni.cz
Úterý Červen 22 12:53:07 CEST 2004


On Tue, Jun 22, 2004 at 12:33:47PM +0200, Martin Špirk wrote:
> 
> zacinam se blize seznamovat s PostgreSQL a neumim vytvorit index podle funkce 
> substr.
> 
> create table pokus(nazev varchar(255));
> create index pnaz on pokus(substr(nazev,1,6));

Na 7.4 projde bez problemu.

> Nevim jestli se to ma zapsat jinak, nebo jak se da takovy index vytvorit?
> 
> Nejak se mu nelibi ty konstanty jako parametry funkce. Pokud jsem zkusil fci 
> ktera ma jeden parametr nebo jsem v podobnem pripade jako druhy a treti index 
> dal ciselne sloupce z tabulky tak to slo. Zkusil jsem si vytvorit vlastni 
> funkci, ktera vracela substr($1,1,6), ale tam to remcalo neco ze index musi 
> byt IMMUTABLE - to nevim co je (a to neresim pravdepodobne vyssi rezii takove 
> funkce).

http://www.postgresql.org/docs/current/static/sql-createindex.html

	 All functions and operators used in an index definition must
	 be "immutable", that is, their results must depend only on
	 their arguments and never on any outside influence (such as
	 the contents of another table or the current time). This
	 restriction ensures that the behavior of the index is
	 well-defined. To use a user-defined function in an index
	 expression or WHERE clause, remember to mark the function
	 immutable when you create it.

-- 
------------------------------------------------------------------------
 Honza Pazdziora | adelton na fi.muni.cz | http://www.fi.muni.cz/~adelton/
 .project: Perl, mod_perl, DBI, Oracle, large Web systems, XML/XSL, ...
		Only self-confident people can be simple.


Další informace o konferenci Test