1. Trang chủ
  2. » Công Nghệ Thông Tin

OReilly practical PostgreSQL jan 2002 ISBN 1565928466

1,3K 87 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 1.327
Dung lượng 3,15 MB

Nội dung

Practical PostgreSQL Prev Next CREATE INDEX Name CREATE INDEX Places an index on a table Synopsis CREATE [ UNIQUE ] INDEX index_name ON table [ USING method ] ( column [ op_class ] [, ] ) CREATE [ UNIQUE ] INDEX index_name ON table [ USING method ] ( func_name ( column [, ] ) [ op_class ] ) Parameters UNIQUE The optional UNIQUE keyword When used, this causes the database to check for, and prevent, duplicate values within the column (or combined columns) it is placed upon This check will occur both when the index is created and each time data is added to the table PostgreSQL will then generate an error whenever an INSERT or UPDATE request is made that would place duplicate data within the index, and the command will fail index_name The name for the new index table The name of the table you are placing the index on method The type of indexing method you wish to use for the index There are three methods available to choose from, the default being btree: btree The PostgreSQL implementation of Lehman-Yao high-concurrency Btrees rtree The PostgreSQL implementation of standard R-trees using Guttman's quadratic split algorithm hash The PostgreSQL implementation of Litwin's linear hashing column The name of the column (or comma-delimited list of columns) on which to place the index op_class The optionally specified associated operator class For most users, this should not be specified func_name The name of a function you wish CREATE INDEX to use on the specified columns (rather than on the data values literally in those columns) The specified function must return a valid value that can be indexed (e.g., not a set of values) Results CREATE The message returned when an index is created successfully ERROR: Cannot create index: 'index_name' already exists The error returned if an index with the name you specified already exists ERROR: DefineIndex: attribute "column" not found The error returned if the specified column does not exist in the specified table to index ERROR: DefineIndex: relation "table" not found The error returned if the specified table does not exist in the connected database Description Use CREATE INDEX to build an optimization index on a specified table, based on one or more of its columns Remember that while indices are designed to improve the performance and effectiveness of your database, using them on tables whose cost of index maintenance outweighs the practical benefit actually decreases overall performance Column index You may create an index specifying a list of one or more table columns This is the "traditional" index type It may be used by queries that directly reference the indexed columns in a WHERE clause Note that R-tree and Hash indices may only index one column, though B-tree indices can index up to sixteen columns Functional index An alternate type of index is one called a functional index A functional index is an index based on the returned value of a function applied to one or more columns Such an index is useful for queries that use the same function in a WHERE clause frequently For example, if you have a query that always references upper(last_name) in its WHERE clause, you could optimized that query by creating a functional index on upper(last_name) Operators and operator classes The PostgreSQL query optimizer will use different indices for different operators used in a comparison It will choose which type of index to used based on the pre-defined list shown in Table 14-1 Table 14-1 Operator/index correspondence Index Operator B- Rtree , @, ~=, && Hash = You can optionally specify an operator class for each column on which an index is placed This is done by setting the optional op_class parameter to the class of operator you intend to use This option only exists because, in some circumstances, there can be more than one meaningful way to order data The default indexing method is generally sufficient for most users, however, and this option is best left unused unless you are creating your own custom types and operators Examples The following example creates a unique index on the id column of the employees table: booktown=# CREATE UNIQUE INDEX employee_id_idx booktown-# ON employees (id); CREATE The next example creates a functional index on the last_name column of the employees table, using the upper() function: booktown=# CREATE INDEX employee_upper_name_idx booktown-# ON employees (upper(last_name)); CREATE Prev CREATE GROUP Home Up Next CREATE LANGUAGE Practical PostgreSQL Prev Next CREATE GROUP Times the parser component pl Times the planner component e Times the executor component The -t and -s options are mutually exclusive -v version The protocol version parameter This option sets the internal version number of the frontend-to-backend protocol -W num The wait parameter Specifying this value causes postgres to wait for num seconds before starting up, allowing a developer time to attach a debugger Prev Multibyte Encoding Types Home Up Next Binary COPY Format Practical PostgreSQL Prev Next Appendix C Binary COPY Format Table of Contents The Header Tuples Trailer In addition to saving data in text format, PostgreSQL can also save COPY output in its own binary format This is the format compiled programs are stored in, which is not readable by normal text editors The Header The PostgreSQL binary file header contains 24 bytes of fixed fields, and a variable length header extension area The fixed fields are as follows: Signature Field A 12-byte sequence, which is literally: PGBCOPY\n\377\r\n\0 The signature is used to identify files that are malformed through a non-8bit-clean transfer; it is changed by dropped NULL values, parity changes, newline translation filters, and dropped high bits Integer Layout Field A 32-byte integer constant (0x01020304) in the source's byte order This is to assist an application reading this file format in preventing byte-flipping of multi-byte values Flags Field A 32-bit integer, which is the main storage point for file formatting information Within this field, bits are ordered from 0 (least significant byte, or LSB) to 31 (most significant byte, or MSB) To hold backwardscompatibility formatting information, bits 0 through 15 are reserved Bits 16 through 31 are used to flag critical file formatting information As of 7.1.x, the only bit here that has a definition is bit 16 BIT 16 If bit 16 is set to 1, object IDs are included in the file If bit 16 is set to 0, object IDs are not included Header Extension Length Field A 32-bit integer describing the length, in bytes, of the remainder of the header (not including the header extension length field) In earlier versions, this was set to zero, and the first tuple immediately followed Prev Backend Options for postgres Home Up Next Tuples Prev Practical PostgreSQL Appendix C Binary COPY Format Next Tuples The structure of tuples within the binary file is as follows: a 16-bit integer count of the fields within the tuple (this is the same within every tuple), a 16-bit integer typlen word, and the field data for each field The available options for the typlen field are as follow: NULL; this field contains no data >0 A fixed-length data type The specified number bytes of data follow the typlen word -1 A varlena data type The next four bytes are the varlena header, consisting of the value's total length (including the length of the header)

Ngày đăng: 19/04/2019, 10:51