PostgreSQLのパーティションテーブル(Simulate Millions Data) - 第2部

PostgreSQLのパーティションテーブル(数百万のデータのシミュレーション)–パート2

PostgreSQLでテーブルパーティションを作成する方法がわからない場合は、Partition Table In PostgreSQL (Create Partition) – Part 1を調べてください。

ここで、百万のデータをパーティションテーブルに挿入する方法を示す簡単な関数を提供します。

--create sequence for testing
CREATE SEQUENCE hashvalue_PT_serial START 1;

--Generate Dynamic data for testing
CREATE OR REPLACE FUNCTION hashvalue_PT_InsertRandomRecords(in a_no_of_records integer) RETURNS integer AS $$
DECLARE
    v_counter integer;
    vhash varchar(255);
    v_date varchar(15);
BEGIN

    v_counter := 1;

    RAISE NOTICE 'No of records insert : %', a_no_of_records;

    WHILE (v_counter <= a_no_of_records) LOOP

    IF( v_counter % 10000 =0) THEN
        RAISE NOTICE 'Counter here is %', v_counter;
    END IF;


    v_date := trunc(random() * 27) +1;
    vhash := '00' || nextval('hashvalue_PT_serial');

    --insert into partiton table
    INSERT INTO hashvalue_pt(
            hash, hashtime)
            VALUES (E'\\003\\002\\001\\0151'::bytea || vhash::bytea , date ('2008-01-' || v_date));
    INSERT INTO hashvalue_pt(
            hash, hashtime)
            VALUES (E'\\003\\002\\001\\0151'::bytea || vhash::bytea, date ('2008-02-' || v_date));
    INSERT INTO hashvalue_pt(
            hash, hashtime)
            VALUES (E'\\003\\002\\001\\0151'::bytea || vhash::bytea, date ('2008-03-' || v_date));
    INSERT INTO hashvalue_pt(
            hash, hashtime)
            VALUES (E'\\003\\002\\001\\0151'::bytea || vhash::bytea, date ('2008-04-' || v_date));
    INSERT INTO hashvalue_pt(
            hash, hashtime)
            VALUES (E'\\003\\002\\001\\0151'::bytea || vhash::bytea, date ('2008-05-' || v_date));
    INSERT INTO hashvalue_pt(
            hash, hashtime)
            VALUES (E'\\003\\002\\001\\0151'::bytea || vhash::bytea , date ('2008-06-' || v_date));
    INSERT INTO hashvalue_pt(
            hash, hashtime)
            VALUES (E'\\003\\002\\001\\0151'::bytea || vhash::bytea, date ('2008-07-' || v_date));
    INSERT INTO hashvalue_pt(
            hash, hashtime)
            VALUES (E'\\003\\002\\001\\0151'::bytea || vhash::bytea, date ('2008-08-' || v_date));
    INSERT INTO hashvalue_pt(
            hash, hashtime)
            VALUES (E'\\003\\002\\001\\0151'::bytea || vhash::bytea, date ('2008-09-' || v_date));
    INSERT INTO hashvalue_pt(
            hash, hashtime)
            VALUES (E'\\003\\002\\001\\0151'::bytea || vhash::bytea, date ('2008-10-' || v_date));


    v_counter := v_counter + 1;

    END LOOP;

    RETURN 0;
END;
$$ LANGUAGE plpgsql;

簡単な「hashvalue_PT_InsertRandomRecords」関数を作成して、パーティションテーブルのパフォーマンステスト用のデータをシミュレートしました。

select * from hashvalue_PT_InsertRandomRecords(20000000);

はっ。 1回の挿入で2億のデータが挿入されます。 さて、10か月で2億のデータがあります。次のセッションでは、パーティションテーブルと非パーティションテーブルの間でパフォーマンステストを開始します。Performance Testing on Partition Table In PostgreSQL – Part 3にアクセスしてください。