Server IP : 103.119.228.120 / Your IP : 3.144.244.244 Web Server : Apache System : Linux v8.techscape8.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64 User : nobody ( 99) PHP Version : 5.6.40 Disable Function : shell_exec,symlink,system,exec,proc_get_status,proc_nice,proc_terminate,define_syslog_variables,syslog,openlog,closelog,escapeshellcmd,passthru,ocinum cols,ini_alter,leak,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dl,dll,myshellexec,proc_open,socket_bind,proc_close,escapeshellarg,parse_ini_filepopen,fpassthru,exec,passthru,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,popen,show_source,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,dl,symlink,shell_exec,system,dl,passthru,escapeshellarg,escapeshellcmd,myshellexec,c99_buff_prepare,c99_sess_put,fpassthru,getdisfunc,fx29exec,fx29exec2,is_windows,disp_freespace,fx29sh_getupdate,fx29_buff_prepare,fx29_sess_put,fx29shexit,fx29fsearch,fx29ftpbrutecheck,fx29sh_tools,fx29sh_about,milw0rm,imagez,sh_name,myshellexec,checkproxyhost,dosyayicek,c99_buff_prepare,c99_sess_put,c99getsource,c99sh_getupdate,c99fsearch,c99shexit,view_perms,posix_getpwuid,posix_getgrgid,posix_kill,parse_perms,parsesort,view_perms_color,set_encoder_input,ls_setcheckboxall,ls_reverse_all,rsg_read,rsg_glob,selfURL,dispsecinfo,unix2DosTime,addFile,system,get_users,view_size,DirFiles,DirFilesWide,DirPrintHTMLHeaders,GetFilesTotal,GetTitles,GetTimeTotal,GetMatchesCount,GetFileMatchesCount,GetResultFiles,fs_copy_dir,fs_copy_obj,fs_move_dir,fs_move_obj,fs_rmdir,SearchText,getmicrotime MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/local/ssl/local/ssl/local/ssl/share/doc/postgresql-9.2.24/html/ |
Upload File : |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >Introduction</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REV="MADE" HREF="mailto:pgsql-docs@postgresql.org"><LINK REL="HOME" TITLE="PostgreSQL 9.2.24 Documentation" HREF="index.html"><LINK REL="UP" TITLE="Indexes" HREF="indexes.html"><LINK REL="PREVIOUS" TITLE="Indexes" HREF="indexes.html"><LINK REL="NEXT" TITLE="Index Types" HREF="indexes-types.html"><LINK REL="STYLESHEET" TYPE="text/css" HREF="stylesheet.css"><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"><META NAME="creation" CONTENT="2017-11-06T22:43:11"></HEAD ><BODY CLASS="SECT1" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="5" ALIGN="center" VALIGN="bottom" ><A HREF="index.html" >PostgreSQL 9.2.24 Documentation</A ></TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A TITLE="Indexes" HREF="indexes.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A HREF="indexes.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="60%" ALIGN="center" VALIGN="bottom" >Chapter 11. Indexes</TD ><TD WIDTH="20%" ALIGN="right" VALIGN="top" ><A TITLE="Index Types" HREF="indexes-types.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="SECT1" ><H1 CLASS="SECT1" ><A NAME="INDEXES-INTRO" >11.1. Introduction</A ></H1 ><P > Suppose we have a table similar to this: </P><PRE CLASS="PROGRAMLISTING" >CREATE TABLE test1 ( id integer, content varchar );</PRE ><P> and the application issues many queries of the form: </P><PRE CLASS="PROGRAMLISTING" >SELECT content FROM test1 WHERE id = <TT CLASS="REPLACEABLE" ><I >constant</I ></TT >;</PRE ><P> With no advance preparation, the system would have to scan the entire <TT CLASS="STRUCTNAME" >test1</TT > table, row by row, to find all matching entries. If there are many rows in <TT CLASS="STRUCTNAME" >test1</TT > and only a few rows (perhaps zero or one) that would be returned by such a query, this is clearly an inefficient method. But if the system has been instructed to maintain an index on the <TT CLASS="STRUCTFIELD" >id</TT > column, it can use a more efficient method for locating matching rows. For instance, it might only have to walk a few levels deep into a search tree. </P ><P > A similar approach is used in most non-fiction books: terms and concepts that are frequently looked up by readers are collected in an alphabetic index at the end of the book. The interested reader can scan the index relatively quickly and flip to the appropriate page(s), rather than having to read the entire book to find the material of interest. Just as it is the task of the author to anticipate the items that readers are likely to look up, it is the task of the database programmer to foresee which indexes will be useful. </P ><P > The following command can be used to create an index on the <TT CLASS="STRUCTFIELD" >id</TT > column, as discussed: </P><PRE CLASS="PROGRAMLISTING" >CREATE INDEX test1_id_index ON test1 (id);</PRE ><P> The name <TT CLASS="STRUCTNAME" >test1_id_index</TT > can be chosen freely, but you should pick something that enables you to remember later what the index was for. </P ><P > To remove an index, use the <TT CLASS="COMMAND" >DROP INDEX</TT > command. Indexes can be added to and removed from tables at any time. </P ><P > Once an index is created, no further intervention is required: the system will update the index when the table is modified, and it will use the index in queries when it thinks doing so would be more efficient than a sequential table scan. But you might have to run the <TT CLASS="COMMAND" >ANALYZE</TT > command regularly to update statistics to allow the query planner to make educated decisions. See <A HREF="performance-tips.html" >Chapter 14</A > for information about how to find out whether an index is used and when and why the planner might choose <SPAN CLASS="emphasis" ><I CLASS="EMPHASIS" >not</I ></SPAN > to use an index. </P ><P > Indexes can also benefit <TT CLASS="COMMAND" >UPDATE</TT > and <TT CLASS="COMMAND" >DELETE</TT > commands with search conditions. Indexes can moreover be used in join searches. Thus, an index defined on a column that is part of a join condition can also significantly speed up queries with joins. </P ><P > Creating an index on a large table can take a long time. By default, <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > allows reads (<TT CLASS="COMMAND" >SELECT</TT > statements) to occur on the table in parallel with index creation, but writes (<TT CLASS="COMMAND" >INSERT</TT >, <TT CLASS="COMMAND" >UPDATE</TT >, <TT CLASS="COMMAND" >DELETE</TT >) are blocked until the index build is finished. In production environments this is often unacceptable. It is possible to allow writes to occur in parallel with index creation, but there are several caveats to be aware of — for more information see <A HREF="sql-createindex.html#SQL-CREATEINDEX-CONCURRENTLY" ><I >Building Indexes Concurrently</I ></A >. </P ><P > After an index is created, the system has to keep it synchronized with the table. This adds overhead to data manipulation operations. Therefore indexes that are seldom or never used in queries should be removed. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="indexes.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="indexes-types.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Indexes</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="indexes.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Index Types</TD ></TR ></TABLE ></DIV ></BODY ></HTML >