提交 4c33c520 编写于 作者: A Ashwin Agrawal

Delete aoco_alter_scenario_test from tinc.

Exact same tests are already covered by alter_table_aocs2.sql in ICW.
上级 b65f2b11
"""
Copyright (c) 2004-Present Pivotal Software, Inc.
This program and the accompanying materials are made available under
the terms of the under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import os
import sys
import glob
from time import sleep
import time
import datetime
import tinctest
from tinctest.lib import local_path, Gpdiff
from mpp.lib.PSQL import PSQL
from gppylib.commands.base import Command
from mpp.models import MPPTestCase
from mpp.lib.gpConfig import GpConfig
from mpp.lib.gprecoverseg import GpRecover
from mpp.gpdb.tests.storage.lib.dbstate import DbStateClass
from mpp.lib.filerep_util import Filerepe2e_Util
class AOCOAlterColumn(MPPTestCase):
def __init__(self):
self.fileutil = Filerepe2e_Util()
self.gprecover = GpRecover()
self.config = GpConfig()
self.base_dir = os.path.dirname(sys.modules[self.__class__.__module__].__file__)
def get_sql_files(self, sql_file_name):
sql_file = os.path.join( self.base_dir, "sql", sql_file_name + ".sql");
return sql_file
def validate_sql(self, ans_file, out_file):
''' Compare the out and ans files '''
init_file=os.path.join( self.base_dir, "sql",'init_file')
result1 = Gpdiff.are_files_equal(out_file, ans_file, match_sub =[init_file])
self.assertTrue(result1 ,'Gpdiff.are_files_equal')
def run_sql(self, filename, out_file,background=False):
''' Run the provided sql and validate it '''
out_file = local_path(filename.replace(".sql", ".out"))
PSQL.run_sql_file(filename,out_file=out_file,background=background)
def run_test_CatalogCheck(self, action,storage):
file_name =action+'_'+storage
sql_file = self.get_sql_files(file_name)
out_file = self.base_dir+ "/sql/"+file_name+'.out'
tinctest.logger.info( 'sql-file == %s \n' % sql_file)
tinctest.logger.info( 'out-file == %s \n' % out_file)
# Run Add/Drop Column script
self.run_sql(sql_file, out_file=out_file)
def validate_test_CatalogCheck(self, action,storage):
file_name =action+'_'+storage
out_file = self.base_dir+ "/sql/"+file_name+'.out'
ans_file = self.base_dir+ "/expected/"+file_name+'.ans'
tinctest.logger.info( 'out-file == %s \n' % out_file)
tinctest.logger.info( 'ans-file == %s \n' % ans_file)
# Validate Ans file
self.validate_sql(ans_file,out_file)
if storage == 'multisegfiles':
''' check if multi_segfile_tab file has multiple segfiles per column '''
tablename='multi_segfile_tab'
relid = self.get_relid(file_name=tablename )
utilitymodeinfo=self.get_utilitymode_conn_info( relid=relid)
u_port=utilitymodeinfo[0]
u_host=utilitymodeinfo[1]
assert(1 < int(self.get_segment_cnt(relid=relid,host=u_host,port= u_port)))
# Check Correctness of the catalog
self.dbstate = DbStateClass('run_validation')
outfile = local_path("gpcheckcat_"+datetime.datetime.fromtimestamp(time.time()).strftime('%Y%m%d%H%M%S')+".out")
self.dbstate.check_catalog(outputFile=outfile)
def get_dbid(self):
sql_cmd = "select min(dbid) dbid from gp_segment_configuration where role = 'p' and status = 'u' and content > -1"
dbid=PSQL.run_sql_command(sql_cmd= sql_cmd,flags='-q -t')
tinctest.logger.info('Segments %s chosen for fault injection' % (dbid))
return dbid
def log_segment_state(self):
sql_cmd = "select * from gp_segment_configuration order by dbid"
result=PSQL.run_sql_command(sql_cmd= sql_cmd)
tinctest.logger.info('==========================')
tinctest.logger.info('State of Segments ')
tinctest.logger.info(result)
tinctest.logger.info('==========================')
def get_segcount_state(self,state):
sql_cmd = "select count(*) from gp_segment_configuration where status = '%s'" % (state)
result=PSQL.run_sql_command(sql_cmd= sql_cmd,flags='-q -t')
tinctest.logger.info('Number of segments in %s State == %d' % (state,(int(result))))
return int(result)
def get_utilitymode_conn_info(self, relid=0):
#get the segment_id where to log in utility mode and then get the hostname and port for this segment
sql_cmd="select port, hostname from gp_segment_configuration sc where dbid > 1 and role = 'p' limit 1;"
utilitymodeinfo=PSQL.run_sql_command(sql_cmd=sql_cmd, flags='-q -t')
u_port=utilitymodeinfo.strip().split('|')[0]
u_host=utilitymodeinfo.strip().split('|')[1]
return [u_port,u_host]
def get_relid(self,file_name=None):
sql_cmd="SELECT oid FROM pg_class WHERE relname='%s';\n" % file_name
relid= PSQL.run_sql_command(sql_cmd=sql_cmd, flags='-q -t')
return relid;
def get_segment_cnt(self, relid=0,host=None,port=None):
sql_cmd="select count(*) from gp_toolkit.__gp_aocsseg(%s) group by column_num having count(*) > 1 limit 1" % (relid)
segcnt=PSQL.run_sql_command_utility_mode(sql_cmd=sql_cmd,host=host, port=port,flags='-q -t')
if (len(segcnt.strip()) == 0):
segcnt='0'
return segcnt
def run_test_utility_mode(self,filename):
#alter_aoco_tab_utilitymode
relid = self.get_relid(file_name=filename )
utilitymodeinfo=self.get_utilitymode_conn_info( relid=relid)
u_port=utilitymodeinfo[0]
u_host=utilitymodeinfo[1]
self.run_sql_utility_mode(filename,host=u_host,port=u_port)
def run_sql_utility_mode(self,filename,host=None,port=None):
fname=filename
sql_file = self.get_sql_files(fname)
out_file = self.base_dir+ "/sql/"+fname +'.out'
ans_file = self.base_dir+ "/expected/"+fname+'.ans'
tinctest.logger.info( '\n==============================')
tinctest.logger.info( sql_file)
tinctest.logger.info( out_file)
tinctest.logger.info( ans_file)
tinctest.logger.info( '==============================')
result=PSQL.run_sql_file_utility_mode(sql_file,out_file=out_file,host=host, port=port)
self.validate_sql(ans_file,out_file)
alter table multi_segfile_tab add column a1 boolean DEFAULT false;
ALTER TABLE
select count(*) as a1 from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='multi_segfile_tab' and attname='a1';
a1
----
1
(1 row)
alter table multivarblock_tab add column a1 boolean DEFAULT false;
ALTER TABLE
select count(*) as a1 from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='multivarblock_tab' and attname='a1';
a1
----
1
(1 row)
--
-- @created 2014-06-06 12:00:00
-- @modified 2014-06-06 12:00:00
-- @tags storage
-- @description AOCO Alter table add column in utility mode - Negative testcase
\d alter_aoco_tab_utilitymode;
Append-Only Columnar Table "public.alter_aoco_tab_utilitymode"
Column | Type | Modifiers
-------------+-----------------------------+-----------
c_custkey | integer |
c_name | character varying(25) |
c_comment | text |
c_rating | double precision |
c_phone | character(15) |
c_acctbal | numeric(15,2) |
c_date | date |
c_timestamp | timestamp without time zone |
Checksum: t
alter table alter_aoco_tab_utilitymode add column add_col1 character varying(35) default 'abc' ;
psql:/path/sql_file:1: ERROR: cannot add column in utility mode, relation alter_aoco_tab_utilitymode, segno 1 (aocssegfiles.c:869)
select count(*) as add_col1 from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='alter_aoco_tab_utilitymode' and attname='add_col1';
add_col1
----------
0
(1 row)
--
-- @created 2014-06-06 12:00:00
-- @modified 2014-06-06 12:00:00
-- @tags storage
-- @description AOCO Alter table add column in utility mode - Negative testcase
\d aoco_tab_utilitymode;
Append-Only Columnar Table "public.aoco_tab_utilitymode"
Column | Type | Modifiers
-------------+-----------------------------+-----------
c_custkey | integer |
c_name | character varying(25) |
c_comment | text |
c_rating | double precision |
c_phone | character(15) |
c_acctbal | numeric(15,2) |
c_date | date |
c_timestamp | timestamp without time zone |
Checksum: t
alter table aoco_tab_utilitymode add column add_col1 character varying(35) default 'abc' ;
psql:/path/sql_file:1: ERROR: internal alter table cannot allocate new relfilenodes (tablecmds.c:5593)
select count(*) as add_col1 from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='aoco_tab_utilitymode' and attname='add_col1';
add_col1
----------
0
(1 row)
--
-- @created 2014-06-06 12:00:00
-- @modified 2014-06-06 12:00:00
-- @tags storage
-- @description AOCO multiple insert to create big table
DROP TABLE IF EXISTS large_aoco_table;
DROP TABLE
CREATE TABLE large_aoco_table (
c_custkey integer,
c_name character varying(25),
c_comment text,
c_rating float,
c_phone character(15),
c_acctbal numeric(15,2),
c_date date,
c_timestamp timestamp
)
WITH (checksum=true, appendonly=true, orientation=column, compresstype=quicklz, compresslevel=1) DISTRIBUTED BY (c_custkey);
CREATE TABLE
insert into large_aoco_table values( 1, 'aa','this is a looong text' , 3.5, '12121212',1000.34,'2015/10/10',now());
INSERT 0 1
insert into large_aoco_table values( 2, 'ab','this is also a looong text' , 4.5, '3456789',3000.45,'2014/08/10',now());
INSERT 0 1
insert into large_aoco_table values( 3, 'ac','this too is a looong text' , 1.5, '878787',500.54,'2014/04/04',now());
INSERT 0 1
insert into large_aoco_table (select i,'xx'||i, 'Can this be a long text please?',i+.5,'10'||i,100.23+i,cast(now() as date),cast(now() as timestamp) from generate_series(1,10000000) i);
INSERT 0 10000000
insert into large_aoco_table (select i,'xx'||i, 'Can this be a long text please?',i+.5,'10'||i,100.23+i,cast(now() as date),cast(now() as timestamp) from generate_series(1,10000000) i);
INSERT 0 10000000
--
-- @created 2014-06-06 12:00:00
-- @modified 2014-06-06 12:00:00
-- @tags storage
-- @description AOCO multiple insert/update to create multiple segfiles
DROP TABLE IF EXISTS multi_segfile_tab;
psql:/path/sql_file:1: NOTICE: table "multi_segfile_tab" does not exist, skipping
DROP TABLE
CREATE TABLE multi_segfile_tab (
c_custkey integer,
c_name character varying(25),
c_comment text,
c_rating float,
c_phone character(15),
c_acctbal numeric(15,2),
c_date date,
c_timestamp timestamp
)
WITH (checksum=true, appendonly=true, orientation=column, compresstype=quicklz, compresslevel=1) DISTRIBUTED BY (c_custkey);
CREATE TABLE
insert into multi_segfile_tab values( 1, 'aa','this is a looong text' , 3.5, '12121212',1000.34,'2015/10/10',now());
INSERT 0 1
insert into multi_segfile_tab values( 2, 'ab','this is also a looong text' , 4.5, '3456789',3000.45,'2014/08/10',now());
INSERT 0 1
insert into multi_segfile_tab values( 3, 'ac','this too is a looong text' , 1.5, '878787',500.54,'2014/04/04',now());
INSERT 0 1
insert into multi_segfile_tab (select i,'xx'||i, 'Can this be a long text please?',i+.5,'10'||i,100.23+i,cast(now() as date),cast(now() as timestamp) from generate_series(100,66900) i);
INSERT 0 66801
update multi_segfile_tab set c_name = 'bcx' where c_custkey % 5 = 0;
UPDATE 13361
vacuum multi_segfile_tab;
VACUUM
insert into multi_segfile_tab (select i,'yy'||i, 'Just another long string',i+.5,'10'||i,100.23+i,cast(now() as date),cast(now() as timestamp) from generate_series(100,6900) i);
INSERT 0 6801
--
-- @created 2014-06-06 12:00:00
-- @modified 2014-06-06 12:00:00
-- @tags storage
-- @description AOCO multiple insert to create multiple var-block
DROP TABLE IF EXISTS multivarblock_tab;
psql:/path/sql_file:1: NOTICE: table "multivarblock_tab" does not exist, skipping
DROP TABLE
CREATE TABLE multivarblock_tab (
c_custkey integer,
c_name character varying(25),
c_comment text,
c_rating float,
c_phone character(15),
c_acctbal numeric(15,2),
c_date date,
c_timestamp timestamp
)
WITH (checksum=true, appendonly=true, orientation=column, compresstype=quicklz, compresslevel=1) DISTRIBUTED BY (c_custkey);
CREATE TABLE
insert into multivarblock_tab values( 1, 'aa','this is a looong text' , 3.5, '12121212',1000.34,'2015/10/10',now());
INSERT 0 1
insert into multivarblock_tab values( 2, 'ab','this is also a looong text' , 4.5, '3456789',3000.45,'2014/08/10',now());
INSERT 0 1
insert into multivarblock_tab values( 3, 'ac','this too is a looong text' , 1.5, '878787',500.54,'2014/04/04',now());
INSERT 0 1
insert into multivarblock_tab (select i,'xx'||i, 'Can this be a long text please?',i+.5,'10'||i,100.23+i,cast(now() as date),cast(now() as timestamp) from generate_series(100,66900) i);
INSERT 0 66801
--
-- @created 2014-06-06 12:00:00
-- @modified 2014-06-06 12:00:00
-- @tags storage
-- @description AOCO Create table for Alter table add column in utility mode - Negative testcase
DROP TABLE IF EXISTS alter_aoco_tab_utilitymode;
psql:/path/sql_file:1: NOTICE: table "alter_aoco_tab_utilitymode" does not exist, skipping
DROP TABLE
CREATE TABLE alter_aoco_tab_utilitymode (
c_custkey integer,
c_name character varying(25),
c_comment text,
c_rating float,
c_phone character(15),
c_acctbal numeric(15,2),
c_date date,
c_timestamp timestamp
)
WITH (checksum=true, appendonly=true, orientation=column) DISTRIBUTED BY (c_custkey);
CREATE TABLE
insert into alter_aoco_tab_utilitymode (select i,'xx'||i, 'This is my long text ',i+.5,'10'||i,100.23+i,cast(now() as date),cast(now() as timestamp) from generate_series(1,1000) i);
INSERT 0 1000
\d alter_aoco_tab_utilitymode;
Append-Only Columnar Table "public.alter_aoco_tab_utilitymode"
Column | Type | Modifiers
-------------+-----------------------------+-----------
c_custkey | integer |
c_name | character varying(25) |
c_comment | text |
c_rating | double precision |
c_phone | character(15) |
c_acctbal | numeric(15,2) |
c_date | date |
c_timestamp | timestamp without time zone |
Checksum: t
Distributed by: (c_custkey)
--
-- @created 2014-05-20 12:00:00
-- @modified 2014-05-20 12:00:00
-- @tags storage
-- @description AOCO table : drop all column one by one then add new col
DROP TABLE IF EXISTS foo;
DROP TABLE
CREATE TABLE foo (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column);
psql:/path/sql_file:1: NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE TABLE
CREATE INDEX foo_index ON foo(b);
CREATE INDEX
INSERT INTO foo SELECT i as a, i as b, 'hello world' as c FROM generate_series(1,50) AS i;
INSERT 0 50
update foo set b=b+10 where a < 3;
UPDATE 2
vacuum foo;
VACUUM
INSERT INTO foo SELECT i as a, i as b, 'hello world again' as c FROM generate_series(51,90) AS i;
INSERT 0 40
select count(*) from foo ;
count
-------
90
(1 row)
ALTER TABLE foo DROP COLUMN c;
ALTER TABLE
select count(*) as c from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='foo' and attname='c';
c
---
0
(1 row)
select count(*) from foo ;
count
-------
90
(1 row)
ALTER TABLE foo DROP COLUMN b;
ALTER TABLE
select count(*) as b from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='foo' and attname='b';
b
---
0
(1 row)
select count(*) from foo ;
count
-------
90
(1 row)
ALTER TABLE foo DROP COLUMN a;
psql:/path/sql_file:1: NOTICE: Dropping a column that is part of the distribution policy forces a NULL distribution policy
ALTER TABLE
select count(*) as a from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='foo' and attname='a';
a
---
0
(1 row)
select count(*) from foo;
count
-------
90
(1 row)
ALTER TABLE foo ADD COLUMN a1 int default 10;
ALTER TABLE
select count(*) as a from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='foo' and attname='a';
a
---
0
(1 row)
select count(*) from foo;
count
-------
90
(1 row)
vacuum foo;
VACUUM
select count(*) from foo;
count
-------
90
(1 row)
--
-- @created 2014-05-20 12:00:00
-- @modified 2014-05-20 12:00:00
-- @tags storage
-- @description AOCO table : drop all column one by one then add new col
DROP TABLE IF EXISTS foo;
DROP TABLE
CREATE TABLE foo (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column);
psql:/path/sql_file:1: NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE TABLE
CREATE INDEX foo_index ON foo(b);
CREATE INDEX
INSERT INTO foo SELECT i as a, i as b, 'hello world' as c FROM generate_series(1,500) AS i;
INSERT 0 500
INSERT INTO foo SELECT i as a, i as b, 'hello world again' as c FROM generate_series(501,900) AS i;
INSERT 0 400
select count(*) from foo ;
count
-------
900
(1 row)
ALTER TABLE foo DROP COLUMN c;
ALTER TABLE
select count(*) as c from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='foo' and attname='c';
c
---
0
(1 row)
select count(*) from foo ;
count
-------
900
(1 row)
ALTER TABLE foo DROP COLUMN b;
ALTER TABLE
select count(*) as b from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='foo' and attname='b';
b
---
0
(1 row)
select count(*) from foo;
count
-------
900
(1 row)
ALTER TABLE foo DROP COLUMN a;
psql:/path/sql_file:1: NOTICE: Dropping a column that is part of the distribution policy forces a NULL distribution policy
ALTER TABLE
select count(*) as a from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='foo' and attname='a';
a
---
0
(1 row)
select count(*) from foo;
count
-------
900
(1 row)
ALTER TABLE foo ADD COLUMN a1 int default 10;
ALTER TABLE
select count(*) as a from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='foo' and attname='a';
a
---
0
(1 row)
select count(*) from foo;
count
-------
900
(1 row)
vacuum foo;
VACUUM
select count(*) from foo;
count
-------
900
(1 row)
alter table large_aoco_table add column add_text_col text default 'this is blah isflsdflsdf ddldl k sdkfmlksdfm lk flksdlslksdlsldkmslkdsdlsdf lskdmlsmfs lsdjlmdfdsfmlsdfkjdsfjn sjkd ksfksdfs lwioemdlksdlk lskdflk lksdfj lksd msdl slkmlmlklskf llwewoweop we dw skdkjsjdlwe wowe lskdl eiwemslksdlkfwiesklslk jsdfkhsdkjfhjh ksdkjdfkjshkjsfksdjfskd kjsdhfsdhfkjsdfksdjfjdskfhksdhfkksjdhfksjdhfksdjhksjdhfksjdkfsjdfhksdhfkjsdkjfhksdjfksdhfksh' ||now() ;
psql:/path/sql_file:1: WARNING: Releasing segworker groups since one or more segment connections failed. This will abort the transactions in the segments that did not get prepared.
psql:/path/sql_file:1: NOTICE: Retry of the distributed transaction 'Abort Prepared' broadcast succeeded to the segments for gid = 1402084958-0000000136.
psql:/path/sql_file:1: ERROR: The distributed transaction 'Prepare' broadcast failed to one or more segments for gid = 1402084958-0000000136. (cdbtm.c:631)
--
-- @created 2014-06-06 12:00:00
-- @modified 2014-06-06 12:00:00
-- @tags storage
-- @description Validate that the alter table add/drop column did not work when a 'panic fault' was introduced as the alter was taking place
\d large_aoco_table
Append-Only Columnar Table "public.large_aoco_table"
Column | Type | Modifiers
-------------+-----------------------------+-----------
c_custkey | integer |
c_name | character varying(25) |
c_comment | text |
c_rating | double precision |
c_phone | character(15) |
c_acctbal | numeric(15,2) |
c_date | date |
c_timestamp | timestamp without time zone |
Checksum: t
Distributed by: (c_custkey)
alter table large_aoco_table add column col2 int default null;
ALTER TABLE
select count(*) as col2 from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='large_aoco_table' and attname='col2';
col2
------
1
(1 row)
alter table multi_segfile_tab add column a1 boolean DEFAULT false;
select count(*) as a1 from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='multi_segfile_tab' and attname='a1';
alter table multivarblock_tab add column a1 boolean DEFAULT false;
select count(*) as a1 from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='multivarblock_tab' and attname='a1';
\d alter_aoco_tab_utilitymode;
alter table alter_aoco_tab_utilitymode add column add_col1 character varying(35) default 'abc' ;
select count(*) as add_col1 from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='alter_aoco_tab_utilitymode' and attname='add_col1';
--
-- @created 2014-04-14 12:00:00
-- @modified 2014-04-14 12:00:00
-- @tags storage
-- @description AOCO table: Alter data type So that a segfile move happens
Drop table if exists change_col_type;
CREATE table change_col_type(i int, j int) with (appendonly=true,orientation=column);
\d change_col_type;
INSERT into change_col_type select i, i+10 from generate_series(1,1000) i;
ALTER table change_col_type alter column j type numeric;
INSERT into change_col_type select i, i+10 from generate_series(1,1000) i;
\d change_col_type;
--
-- @created 2014-05-20 12:00:00
-- @modified 2014-05-20 12:00:00
-- @tags storage
-- @description AOCO table : drop all column one by one then add new col
DROP TABLE IF EXISTS foo;
CREATE TABLE foo (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column);
CREATE INDEX foo_index ON foo(b);
INSERT INTO foo SELECT i as a, i as b, 'hello world' as c FROM generate_series(1,500) AS i;
INSERT INTO foo SELECT i as a, i as b, 'hello world again' as c FROM generate_series(501,900) AS i;
select * from foo order by a,b;
ALTER TABLE foo DROP COLUMN c;
select count(*) as c from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='foo' and attname='c';
select * from foo order by a,b;
ALTER TABLE foo DROP COLUMN b;
select count(*) as b from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='foo' and attname='b';
select * from foo order by a;
ALTER TABLE foo DROP COLUMN a;
select count(*) as a from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='foo' and attname='a';
select * from foo;
ALTER TABLE foo ADD COLUMN a1 int default 10;
select count(*) as a from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='foo' and attname='a';
select * from foo;
vacuum foo;
select * from foo;
--
-- @created 2014-04-14 12:00:00
-- @modified 2014-04-14 12:00:00
-- @tags storage
-- @description AOCO compressed table : alter add all types of columns
DROP TABLE if exists aoco_allalter;
DROP TABLE if exists aoco_allalter_uncompr;
--CREATE TABLE aoco_allalter (id SERIAL, DEFAULT COLUMN ENCODING (compresstype=zlib,blocksize=8192,compresslevel=1)) WITH (appendonly=true, orientation=column) distributed randomly ;
CREATE TABLE aoco_allalter (id SERIAL, DEFAULT COLUMN ENCODING (compresstype=zlib,blocksize=8192,compresslevel=1),num int) WITH (appendonly=true, orientation=column) distributed randomly ;
insert into aoco_allalter select i from generate_series(1,100) i;
update aoco_allalter set num = num + 10 where id < 10;
vacuum aoco_allalter;
insert into aoco_allalter select i from generate_series(101,500) i;
-- Alter all kinds of columns
Alter table aoco_allalter ADD COLUMN a1 int default 10 ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a2 char(5) default 'asdf' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a3 numeric default 3.14 ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a4 boolean DEFAULT false ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a5 char DEFAULT 'd' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a6 text default 'some default value' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a7 timestamp default '2003-10-21 02:26:11' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a8 character varying(705) default 'asdsdsfdsnfdsnafkndasfdsajfldsjafdsbfjdsbfkdsjf' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a9 bigint default 2342 ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a10 date default '1989-11-12' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a11 varchar(600) default 'ksdhfkdshfdshfkjhdskjfhdshflkdshfhdsfkjhds' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a12 text default 'mnsbfsndlsjdflsjasdjhhsafhshfsljlsahfkshalsdkfks' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a13 decimal default 4.123 ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a14 real default 23232 ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a15 bigint default 2342 ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a16 int4 default 2342 ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a17 bytea default '0011' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a18 timestamp with time zone default '1995-07-16 01:51:15+1359' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a19 timetz default '1991-12-13 01:51:15' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a20 path default '((6,7),(4,5),(2,1))' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a21 box default '((1,3)(4,6))' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a22 macaddr default '09:00:3b:01:02:03' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a23 interval default '5-7' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a24 character varying(800) default 'jdgfkasdksahkjcskgcksgckdsfkdslfhksagfksajhdjag' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a25 lseg default '((1,2)(2,3))' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a26 point default '(3,4)' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a27 double precision default 12.211 ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a28 circle default '((2,3),4)' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a29 int4 default 37 ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a30 numeric(8) default 3774 ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a31 polygon default '(1,5,4,3)' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a32 date default '1988-02-21' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a33 real default 41114 ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a34 money default '$7,222.00' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a35 cidr default '192.167.2' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a36 inet default '126.2.3.4' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a37 time default '10:31:45' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a38 text default 'sdhjfsfksfkjskjfksjfkjsdfkjdshkjfhdsjkfkjsd' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a39 bit default '0' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a40 bit varying(5) default '1' ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a41 smallint default 12 ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
Alter table aoco_allalter ADD COLUMN a42 int default 2323 ENCODING (compresstype=quicklz,compresslevel=1,blocksize=8192);
--
-- Insert data to the table
--
INSERT INTO aoco_allalter(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31,a32,a33,a34,a35,a36,a37,a38,a39,a40,a41,a42) values(generate_series(1,20),'M',2011,'t','a','This is news of today: Deadlock between Republicans and Democrats over how best to reduce the U.S. deficit, and over what period, has blocked an agreement to allow the raising of the $14.3 trillion debt ceiling','2001-12-24 02:26:11','U.S. House of Representatives Speaker John Boehner, the top Republican in Congress who has put forward a deficit reduction plan to be voted on later on Thursday said he had no control over whether his bill would avert a credit downgrade.',generate_series(2490,2505),'2011-10-11','The Republican-controlled House is tentatively scheduled to vote on Boehner proposal this afternoon at around 6 p.m. EDT (2200 GMT). The main Republican vote counter in the House, Kevin McCarthy, would not say if there were enough votes to pass the bill.','WASHINGTON:House Speaker John Boehner says his plan mixing spending cuts in exchange for raising the nations $14.3 trillion debt limit is not perfect but is as large a step that a divided government can take that is doable and signable by President Barack Obama.The Ohio Republican says the measure is an honest and sincere attempt at compromise and was negotiated with Democrats last weekend and that passing it would end the ongoing debt crisis. The plan blends $900 billion-plus in spending cuts with a companion increase in the nations borrowing cap.','1234.56',323453,generate_series(3452,3462),7845,'0011','2005-07-16 01:51:15+1359','2001-12-13 01:51:15','((1,2),(0,3),(2,1))','((2,3)(4,5))','08:00:2b:01:02:03','1-2','Republicans had been working throughout the day Thursday to lock down support for their plan to raise the nations debt ceiling, even as Senate Democrats vowed to swiftly kill it if passed.','((2,3)(4,5))','(6,7)',11.222,'((4,5),7)',32,3214,'(1,0,2,3)','2010-02-21',43564,'$1,000.00','192.168.1','126.1.3.4','12:30:45','Johnson & Johnsons McNeil Consumer Healthcare announced the voluntary dosage reduction today. Labels will carry new dosing instructions this fall.The company says it will cut the maximum dosage of Regular Strength Tylenol and other acetaminophen-containing products in 2012.Acetaminophen is safe when used as directed, says Edwin Kuffner, MD, McNeil vice president of over-the-counter medical affairs. But, when too much is taken, it can cause liver damage.The action is intended to cut the risk of such accidental overdoses, the company says in a news release.','1','0',12,23);
--
--Alter table set distributed by
ALTER table aoco_allalter set with ( reorganize='true') distributed by (a1);
-- Create Uncompressed table of same schema definition
CREATE TABLE aoco_allalter_uncompr (id SERIAL,a1 int,a2 char(5),a3 numeric,a4 boolean DEFAULT false ,a5 char DEFAULT 'd',a6 text,a7 timestamp,a8 character varying(705),a9 bigint,a10 date,a11 varchar(600),a12 text,a13 decimal,a14 real,a15 bigint,a16 int4 ,a17 bytea,a18 timestamp with time zone,a19 timetz,a20 path,a21 box,a22 macaddr,a23 interval,a24 character varying(800),a25 lseg,a26 point,a27 double precision,a28 circle,a29 int4,a30 numeric(8),a31 polygon,a32 date,a33 real,a34 money,a35 cidr,a36 inet,a37 time,a38 text,a39 bit,a40 bit varying(5),a41 smallint,a42 int) WITH (appendonly=true, orientation=column) distributed randomly;
--
-- Insert to uncompressed table
--
INSERT INTO aoco_allalter_uncompr(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31,a32,a33,a34,a35,a36,a37,a38,a39,a40,a41,a42) values(generate_series(1,20),'M',2011,'t','a','This is news of today: Deadlock between Republicans and Democrats over how best to reduce the U.S. deficit, and over what period, has blocked an agreement to allow the raising of the $14.3 trillion debt ceiling','2001-12-24 02:26:11','U.S. House of Representatives Speaker John Boehner, the top Republican in Congress who has put forward a deficit reduction plan to be voted on later on Thursday said he had no control over whether his bill would avert a credit downgrade.',generate_series(2490,2505),'2011-10-11','The Republican-controlled House is tentatively scheduled to vote on Boehner proposal this afternoon at around 6 p.m. EDT (2200 GMT). The main Republican vote counter in the House, Kevin McCarthy, would not say if there were enough votes to pass the bill.','WASHINGTON:House Speaker John Boehner says his plan mixing spending cuts in exchange for raising the nations $14.3 trillion debt limit is not perfect but is as large a step that a divided government can take that is doable and signable by President Barack Obama.The Ohio Republican says the measure is an honest and sincere attempt at compromise and was negotiated with Democrats last weekend and that passing it would end the ongoing debt crisis. The plan blends $900 billion-plus in spending cuts with a companion increase in the nations borrowing cap.','1234.56',323453,generate_series(3452,3462),7845,'0011','2005-07-16 01:51:15+1359','2001-12-13 01:51:15','((1,2),(0,3),(2,1))','((2,3)(4,5))','08:00:2b:01:02:03','1-2','Republicans had been working throughout the day Thursday to lock down support for their plan to raise the nations debt ceiling, even as Senate Democrats vowed to swiftly kill it if passed.','((2,3)(4,5))','(6,7)',11.222,'((4,5),7)',32,3214,'(1,0,2,3)','2010-02-21',43564,'$1,000.00','192.168.1','126.1.3.4','12:30:45','Johnson & Johnsons McNeil Consumer Healthcare announced the voluntary dosage reduction today. Labels will carry new dosing instructions this fall.The company says it will cut the maximum dosage of Regular Strength Tylenol and other acetaminophen-containing products in 2012.Acetaminophen is safe when used as directed, says Edwin Kuffner, MD, McNeil vice president of over-the-counter medical affairs. But, when too much is taken, it can cause liver damage.The action is intended to cut the risk of such accidental overdoses, the company says in a news release.','1','0',12,23);
\d+ aoco_allalter
--Select from pg_attribute_encoding to see the table entry
select attrelid::regclass as relname, attnum, attoptions from pg_class c, pg_attribute_encoding e where c.relname = 'aoco_allalter' and c.oid=e.attrelid order by relname, attnum limit 3;
--
-- Compare data with uncompressed table
--
--
-- Select number of rows from the uncompressed table
--
SELECT count(*) as count_uncompressed from aoco_allalter_uncompr ;
--
-- Select number of rows from the compressed table
--
SELECT count(*) as count_compressed from aoco_allalter;
--
-- Select number of rows using a FULL outer join on all the columns of the two tables
-- Count should match with above result if the all the rows uncompressed correctly:
--
Select count(*) as count_join from aoco_allalter t1 full outer join aoco_allalter_uncompr t2 on t1.id=t2.id and t1.a1=t2.a1 and t1.a2=t2.a2 and t1.a3=t2.a3 and t1.a4=t2.a4 and t1.a5=t2.a5 and t1.a6=t2.a6 and t1.a7=t2.a7 and t1.a8=t2.a8 and t1.a9=t2.a9 and t1.a10=t2.a10 and t1.a11=t2.a11 and t1.a12=t2.a12 and t1.a13=t2.a13 and t1.a14=t2.a14 and t1.a15=t2.a15 and t1.a16=t2.a16 and t1.a17=t2.a17 and t1.a18=t2.a18 and t1.a19=t2.a19 and t1.a22=t2.a22 and t1.a23=t2.a23 and t1.a24=t2.a24 and t1.a27=t2.a27 and t1.a29=t2.a29 and t1.a30=t2.a30 and t1.a32=t2.a32 and t1.a33=t2.a33 and t1.a34=t2.a34 and t1.a35=t2.a35 and t1.a36=t2.a36 and t1.a37=t2.a37 and t1.a38=t2.a38 and t1.a39=t2.a39 and t1.a40=t2.a40 and t1.a41=t2.a41 and t1.a42=t2.a42 ;
--
-- Truncate the table
--
TRUNCATE table aoco_allalter;
--
-- Insert data again
--
insert into aoco_allalter select * from aoco_allalter_uncompr order by a1;
--
-- Select the data: Using the JOIN as mentioned above
--
Select count(*) as count_join from aoco_allalter t1 full outer join aoco_allalter_uncompr t2 on t1.id=t2.id and t1.a1=t2.a1 and t1.a2=t2.a2 and t1.a3=t2.a3 and t1.a4=t2.a4 and t1.a5=t2.a5 and t1.a6=t2.a6 and t1.a7=t2.a7 and t1.a8=t2.a8 and t1.a9=t2.a9 and t1.a10=t2.a10 and t1.a11=t2.a11 and t1.a12=t2.a12 and t1.a13=t2.a13 and t1.a14=t2.a14 and t1.a15=t2.a15 and t1.a16=t2.a16 and t1.a17=t2.a17 and t1.a18=t2.a18 and t1.a19=t2.a19 and t1.a22=t2.a22 and t1.a23=t2.a23 and t1.a24=t2.a24 and t1.a27=t2.a27 and t1.a29=t2.a29 and t1.a30=t2.a30 and t1.a32=t2.a32 and t1.a33=t2.a33 and t1.a34=t2.a34 and t1.a35=t2.a35 and t1.a36=t2.a36 and t1.a37=t2.a37 and t1.a38=t2.a38 and t1.a39=t2.a39 and t1.a40=t2.a40 and t1.a41=t2.a41 and t1.a42=t2.a42 ;
--Alter table alter type of a column
Alter table aoco_allalter Alter column a3 TYPE int4;
--Insert data to the table, select count(*)
Insert into aoco_allalter(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31,a32,a33,a34,a35,a36,a37,a38,a39,a40,a41,a42) select a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31,a32,a33,a34,a35,a36,a37,a38,a39,a40,a41,a42 from aoco_allalter where id =10;
Select count(*) from aoco_allalter;
--Alter table drop a column
Alter table aoco_allalter Drop column a12;
Insert into aoco_allalter(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31,a32,a33,a34,a35,a36,a37,a38,a39,a40,a41,a42) select a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31,a32,a33,a34,a35,a36,a37,a38,a39,a40,a41,a42 from aoco_allalter where id =10;
Select count(*) from aoco_allalter;
--Alter table rename a column
Alter table aoco_allalter Rename column a13 TO after_rename_a13;
--Insert data to the table, select count(*)
Insert into aoco_allalter(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,after_rename_a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31,a32,a33,a34,a35,a36,a37,a38,a39,a40,a41,a42) select a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,after_rename_a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31,a32,a33,a34,a35,a36,a37,a38,a39,a40,a41,a42 from aoco_allalter where id =10;
Select count(*) from aoco_allalter;
update aoco_allalter set a9 = a9 + 10 where a1 = 10;
--
-- @created 2014-06-06 12:00:00
-- @modified 2014-06-06 12:00:00
-- @tags storage
-- @description AOCO multiple insert to create big table
DROP TABLE IF EXISTS large_aoco_table;
CREATE TABLE large_aoco_table (
c_custkey integer,
c_name character varying(25),
c_comment text,
c_rating float,
c_phone character(15),
c_acctbal numeric(15,2),
c_date date,
c_timestamp timestamp
)
WITH (checksum=true, appendonly=true, orientation=column, compresstype=quicklz, compresslevel=1) DISTRIBUTED BY (c_custkey);
insert into large_aoco_table values( 1, 'aa','this is a looong text' , 3.5, '12121212',1000.34,'2015/10/10',now());
insert into large_aoco_table values( 2, 'ab','this is also a looong text' , 4.5, '3456789',3000.45,'2014/08/10',now());
insert into large_aoco_table values( 3, 'ac','this too is a looong text' , 1.5, '878787',500.54,'2014/04/04',now());
insert into large_aoco_table (select i,'xx'||i, 'Can this be a long text please?',i+.5,'10'||i,100.23+i,cast(now() as date),cast(now() as timestamp) from generate_series(1,10000000) i);
insert into large_aoco_table (select i,'xx'||i, 'Can this be a long text please?',i+.5,'10'||i,100.23+i,cast(now() as date),cast(now() as timestamp) from generate_series(1,10000000) i);
--
-- @created 2014-06-06 12:00:00
-- @modified 2014-06-06 12:00:00
-- @tags storage
-- @description AOCO multiple insert/update to create multiple segfiles
DROP TABLE IF EXISTS multi_segfile_tab;
CREATE TABLE multi_segfile_tab (
c_custkey integer,
c_name character varying(25),
c_comment text,
c_rating float,
c_phone character(15),
c_acctbal numeric(15,2),
c_date date,
c_timestamp timestamp
)
WITH (checksum=true, appendonly=true, orientation=column, compresstype=quicklz, compresslevel=1) DISTRIBUTED BY (c_custkey);
insert into multi_segfile_tab values( 1, 'aa','this is a looong text' , 3.5, '12121212',1000.34,'2015/10/10',now());
insert into multi_segfile_tab values( 2, 'ab','this is also a looong text' , 4.5, '3456789',3000.45,'2014/08/10',now());
insert into multi_segfile_tab values( 3, 'ac','this too is a looong text' , 1.5, '878787',500.54,'2014/04/04',now());
insert into multi_segfile_tab (select i,'xx'||i, 'Can this be a long text please?',i+.5,'10'||i,100.23+i,cast(now() as date),cast(now() as timestamp) from generate_series(100,66900) i);
update multi_segfile_tab set c_name = 'bcx' where c_custkey % 5 = 0;
vacuum multi_segfile_tab;
insert into multi_segfile_tab (select i,'yy'||i, 'Just another long string',i+.5,'10'||i,100.23+i,cast(now() as date),cast(now() as timestamp) from generate_series(100,6900) i);
--
-- @created 2014-06-06 12:00:00
-- @modified 2014-06-06 12:00:00
-- @tags storage
-- @description AOCO multiple insert to create multiple var-block
DROP TABLE IF EXISTS multivarblock_tab;
CREATE TABLE multivarblock_tab (
c_custkey integer,
c_name character varying(25),
c_comment text,
c_rating float,
c_phone character(15),
c_acctbal numeric(15,2),
c_date date,
c_timestamp timestamp
)
WITH (checksum=true, appendonly=true, orientation=column, compresstype=quicklz, compresslevel=1) DISTRIBUTED BY (c_custkey);
insert into multivarblock_tab values( 1, 'aa','this is a looong text' , 3.5, '12121212',1000.34,'2015/10/10',now());
insert into multivarblock_tab values( 2, 'ab','this is also a looong text' , 4.5, '3456789',3000.45,'2014/08/10',now());
insert into multivarblock_tab values( 3, 'ac','this too is a looong text' , 1.5, '878787',500.54,'2014/04/04',now());
insert into multivarblock_tab (select i,'xx'||i, 'Can this be a long text please?',i+.5,'10'||i,100.23+i,cast(now() as date),cast(now() as timestamp) from generate_series(100,66900) i);
--
-- @created 2014-06-06 12:00:00
-- @modified 2014-06-06 12:00:00
-- @tags storage
-- @description AOCO Create table for Alter table add column in utility mode - Negative testcase
DROP TABLE IF EXISTS alter_aoco_tab_utilitymode;
CREATE TABLE alter_aoco_tab_utilitymode (
c_custkey integer,
c_name character varying(25),
c_comment text,
c_rating float,
c_phone character(15),
c_acctbal numeric(15,2),
c_date date,
c_timestamp timestamp
)
WITH (checksum=true, appendonly=true, orientation=column) DISTRIBUTED BY (c_custkey);
insert into alter_aoco_tab_utilitymode (select i,'xx'||i, 'This is my long text ',i+.5,'10'||i,100.23+i,cast(now() as date),cast(now() as timestamp) from generate_series(1,1000) i);
\d alter_aoco_tab_utilitymode;
--
-- @created 2014-05-20 12:00:00
-- @modified 2014-05-20 12:00:00
-- @tags storage
-- @description AOCO table : drop all column one by one then add new col
DROP TABLE IF EXISTS foo;
CREATE TABLE foo (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column);
CREATE INDEX foo_index ON foo(b);
INSERT INTO foo SELECT i as a, i as b, 'hello world' as c FROM generate_series(1,50) AS i;
update foo set b=b+10 where a < 3;
vacuum foo;
INSERT INTO foo SELECT i as a, i as b, 'hello world again' as c FROM generate_series(51,90) AS i;
select count(*) from foo ;
ALTER TABLE foo DROP COLUMN c;
select count(*) as c from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='foo' and attname='c';
select count(*) from foo ;
ALTER TABLE foo DROP COLUMN b;
select count(*) as b from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='foo' and attname='b';
select count(*) from foo ;
ALTER TABLE foo DROP COLUMN a;
select count(*) as a from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='foo' and attname='a';
select count(*) from foo;
ALTER TABLE foo ADD COLUMN a1 int default 10;
select count(*) as a from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='foo' and attname='a';
select count(*) from foo;
vacuum foo;
select count(*) from foo;
--
-- @created 2014-05-20 12:00:00
-- @modified 2014-05-20 12:00:00
-- @tags storage
-- @description AOCO table : drop all column one by one then add new col
DROP TABLE IF EXISTS foo;
CREATE TABLE foo (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column);
CREATE INDEX foo_index ON foo(b);
INSERT INTO foo SELECT i as a, i as b, 'hello world' as c FROM generate_series(1,500) AS i;
INSERT INTO foo SELECT i as a, i as b, 'hello world again' as c FROM generate_series(501,900) AS i;
select count(*) from foo ;
ALTER TABLE foo DROP COLUMN c;
select count(*) as c from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='foo' and attname='c';
select count(*) from foo ;
ALTER TABLE foo DROP COLUMN b;
select count(*) as b from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='foo' and attname='b';
select count(*) from foo;
ALTER TABLE foo DROP COLUMN a;
select count(*) as a from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='foo' and attname='a';
select count(*) from foo;
ALTER TABLE foo ADD COLUMN a1 int default 10;
select count(*) as a from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='foo' and attname='a';
select count(*) from foo;
vacuum foo;
select count(*) from foo;
-- start_matchsubs
-- m/ /
-- s/\[\/.+\]/[PATH]/
-- m/DETAIL:/
-- s/gpfdist.+/ DUMMY_LOCATION /
-- m/psql:/
-- s/psql:.+\//PATH1\//
-- m/(\d+)\.(\d+)\.(\d+)\.(\d+)/
-- s/(\d+)\.(\d+)\.(\d+)\.(\d+)/HOST/g
-- m/ /
-- s/\s+\(.*\.[ch]:\d+\)/ (SOMEFILE:SOMEFUNC)/
-- m/ /
-- s/\s+\(.*\.[ch]:\d+\)/ (faultinjector.c:xxx)/
-- m/transaction \d+/
-- s/transaction \d+/transaction /
-- m/transaction -\d+/
-- s/transaction -\d+/transaction/
-- end_matchsubs
-- start_matchignore
--
-- m/WARNING\:\s+skipping.*cannot vacuum indexes, views, external tables/
--
-- m/WARNING\: The distributed transaction 'Commit Prepared' broadcast failed to one or more segments for gid/
-- m/NOTICE\: Releasing gangs for retry broadcast/
-- m/NOTICE\: Retry of the distributed transaction \'Commit Prepared\' broadcast succeeded to the segments for gid/
-- m/DETAIL\:*/
-- m/HINT\:/
-- m/CONTEXT\:/
-- m/WARNING\: mirror failure/
-- m/position /
-- m/failover requested /
-- m/\'waiting for ack\'/
--
-- end_matchignore
alter table large_aoco_table add column add_text_col text default 'this is blah isflsdflsdf ddldl k sdkfmlksdfm lk flksdlslksdlsldkmslkdsdlsdf lskdmlsmfs lsdjlmdfdsfmlsdfkjdsfjn sjkd ksfksdfs lwioemdlksdlk lskdflk lksdfj lksd msdl slkmlmlklskf llwewoweop we dw skdkjsjdlwe wowe lskdl eiwemslksdlkfwiesklslk jsdfkhsdkjfhjh ksdkjdfkjshkjsfksdjfskd kjsdhfsdhfkjsdfksdjfjdskfhksdhfkksjdhfksjdhfksdjhksjdhfksjdkfsjdfhksdhfkjsdkjfhksdjfksdhfksh' ||now() ;
--
-- @created 2014-06-06 12:00:00
-- @modified 2014-06-06 12:00:00
-- @tags storage
-- @description Validate that the alter table add/drop column did not work when a 'panic fault' was introduced as the alter was taking place
\d large_aoco_table
alter table large_aoco_table add column col2 int default null;
select count(*) as col2 from pg_attribute pa, pg_class pc where pa.attrelid = pc.oid and pc.relname='large_aoco_table' and attname='col2';
"""
Copyright (c) 2004-Present Pivotal Software, Inc.
This program and the accompanying materials are made available under
the terms of the under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import os
import glob
import sys
import tinctest
from tinctest.lib import local_path, Gpdiff
from mpp.models import MPPTestCase
from tinctest.models.scenario import ScenarioTestCase
from mpp.lib.PSQL import PSQL
from mpp.gpdb.tests.storage.aoco_alter.aoco_alter_scenario_test.aocoAlterColumn import AOCOAlterColumn
class AOCSAlterColumnTestCase(ScenarioTestCase, MPPTestCase):
''' Testing the performance enhancement related changes done to alter table add/drop column to aoco tables '''
def __init__(self, methodName):
super(AOCSAlterColumnTestCase,self).__init__(methodName)
self.aoco_alt_obj=AOCOAlterColumn()
@classmethod
def setUpClass(cls):
super(AOCSAlterColumnTestCase, cls).setUpClass()
'''
Create tables with multiple varblocks and multiple segfiles upfront. They will be used in the tests .
'''
base_dir = os.path.dirname(sys.modules[cls.__module__].__file__)
crtable_name = ['create_tabfor_utility_mode','create_multivarblock_table','create_multisegfile_table','create_large_table']
for sname in crtable_name:
aoco_alter_sql=''
aoco_alter_sql= os.path.join(os.path.dirname(sys.modules[cls.__module__].__file__), "sql")+'/'+sname+'.sql'
aoco_alter_ans= os.path.join(os.path.dirname(sys.modules[cls.__module__].__file__), "expected")+'/'+sname+'.ans'
aoco_alter_out= os.path.join(os.path.dirname(sys.modules[cls.__module__].__file__), "sql")+'/'+sname+'.out'
tinctest.logger.info( '\n Creating TABLE : %s' % aoco_alter_sql )
res=PSQL.run_sql_file(sql_file = aoco_alter_sql,out_file=aoco_alter_out)
init_file=os.path.join( base_dir, "sql",'init_file')
result = Gpdiff.are_files_equal(aoco_alter_out, aoco_alter_ans, match_sub =[init_file])
errmsg='Gpdiff are not equal for file '+ sname
assert result, errmsg
def test_NegativeAOCOAlter_UtilityMode_06_addcolumn_utilityMode(self):
'''
@product_version gpdb: [4.3.2.0-]
This tests the behavior of alter table in a utility mode connection
STEPS:
1. Make a Utlity Mode connection
2. Alter table add column
3. Make sure the alter fails
'''
tinctest.logger.info("\n ===============================================")
tinctest.logger.info("\n Starting Test: test_NegativeAOCOAlter_UtilityMode_06_addcolumn_utilityMode")
tinctest.logger.info("\n ===============================================")
self.aoco_alt_obj.run_test_utility_mode('alter_aoco_tab_utilitymode')
def test_AOCOAlterColumnCatalogCheck(self):
'''
@product_version gpdb: [4.3.2.0-]
These set of tests verify the correctness of catalog after alter table add/drop column
involving multi-varblock and multi-segfile Appendonly column oriented table
STEPS:
1. perform alter table add/drop column to multi-varblock/multi-segfile
2. Verify the correctness of the operation
3. Use gpcheckcat to validate the correctness of catalog after alter table operation
@data_provider data_types_provider
'''
tinctest.logger.info("\n ===============================================")
tinctest.logger.info("\n Starting Test: %s%s " % (self.test_data[0][0], self.test_data[0][1] ))
action = self.test_data[1][0]
storage= self.test_data[1][1]
tinctest.logger.info("\n SQL Action : %s" %(action))
tinctest.logger.info("\n Storage type : %s" %(storage))
tinctest.logger.info("\n ===============================================")
self.aoco_alt_obj.run_test_CatalogCheck(action,storage)
self.aoco_alt_obj.validate_test_CatalogCheck(action,storage)
@tinctest.dataProvider('data_types_provider')
def test_data_provider():
data = {
'01_addcol_multisegfiles': ['addcol','multisegfiles']
,'02_dropcol_multisegfiles': ['dropcol','multisegfiles']
,'03_addcol_multivarblock': ['addcol','multivarblock']
,'04_dropcol_multivarblock': ['dropcol','multivarblock']
}
return data
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册