ITPub博客

首页 > Linux操作系统 > Linux操作系统 > DB2_创建重组索引

DB2_创建重组索引

原创 Linux操作系统 作者:redhouser 时间:2011-07-15 14:35:35 0 删除 编辑

目的:
测试DB2创建重组索引,本脚本摘录自DB2安装目录/admin_scripts/tbonlineinx.db2。
版本:Windows DB2 Express-C V9.7

操作步骤:
使用"db2cmd db2 -t"进入交互模式,执行后续操作。

-- connect to sample database
CONNECT TO SAMPLE;

1,创建索引
-- create an index on a table with different levels of access to the table
-- like read-write, read-only, no access

-- create an online index with read-write access to the table
CREATE INDEX index1 ON employee (lastname ASC);

-- drop the index
DROP INDEX index1;

-- create an index on a table while allowing only read access to it
LOCK TABLE employee IN SHARE MODE;

CREATE INDEX index1 ON employee (lastname ASC);

-- drop the index
DROP INDEX index1;

-- create an online index allowing no access to the table
LOCK TABLE employee IN EXCLUSIVE MODE;

CREATE INDEX index1 ON employee (lastname ASC);

-- reorg online index on the table

2,重组索引
-- reorganize the indexes on the table allowing read-write
REORG INDEXES ALL FOR TABLE employee
  ALLOW WRITE ACCESS
  ON ALL DBPARTITIONNUMS;

-- reorganize the indexes on the table allowing read-only
REORG INDEXES ALL FOR TABLE employee
  ALLOW READ ACCESS
  ON ALL DBPARTITIONNUMS;

-- reorganize the indexes on the table allowing no access
REORG INDEXES ALL FOR TABLE employee
  ALLOW NO ACCESS
  ON ALL DBPARTITIONNUMS;

-- drop the index
DROP INDEX index1;

3,创建超常列索引
-- create bufferpool with 32K pagesize
CREATE BUFFERPOOL bupl32k SIZE 500 PAGESIZE 32K;

-- create tablespace using above created bufferpool
CREATE TABLESPACE tbsp32k
  PAGESIZE 32k
  MANAGED BY DATABASE
  USING (FILE 'tbsp32k' 500)
  BUFFERPOOL bupl32k;

-- create table with large coloumn size.
CREATE TABLE inventory_ident (dept INTEGER,
                              serial_numbers VARCHAR(8190) NOT NULL)
  IN tbsp32k;

-- create a system temporary table space with 32K pages.
-- When the INDEXSORT database configuration parameter is set to Yes
-- (which is the default), then that data is sorted before it is passed
-- to index manager. If sort heap is big enough for the amount of data
-- being sorted, the sort will occur entirely in memory.  However, just
-- in case we need to spill to disk, DB2 will ensure that there is a
-- system temporary tablespace with a large enough page size to spill to.

CREATE SYSTEM TEMPORARY TABLESPACE tmptbsp32k
  PAGESIZE 32K
  MANAGED BY SYSTEM
  USING ('tmp_tbsp_32k')
  EXTENTSIZE 2
  BUFFERPOOL bupl32k;

-- create an index on the serial_numbers column
-- The upper bound for an index key length is variable based on 
-- page size. The maximum length of an index key part can be:   
-- 1024 bytes for 1K page size,
-- 2048 bytes for 8K page size,
-- 4096 bytes for 16K page size,
-- 8192 bytes for 32K page size,
-- and, the index name can be upto 128 char
CREATE INDEX inventory_serial_number_index_ident
  ON inventory_ident (serial_numbers);

-- perform. cleanup
DROP INDEX inventory_serial_number_index_ident;
DROP TABLE inventory_ident;
DROP TABLESPACE tmptbsp32k;
DROP TABLESPACE tbsp32k;
DROP BUFFERPOOL bupl32k;

-- disconnect from the database
CONNECT RESET;
TERMINATE;

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/18922393/viewspace-702298/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: DB2_行压缩
请登录后发表评论 登录
全部评论

注册时间:2011-05-26

  • 博文量
    211
  • 访问量
    876684