2017/9/7 db tech showcase Tokyo 2017(JPOUG in 15 minutes)にて発表した内容です。
SQL大量発行に伴う処理遅延は、ミッションクリティカルシステムでありがちな性能問題のひとつです。
SQLをまとめて発行したり、処理の多重度を上げることができれば高速化可能です。ですが???
AP設計に起因する性能問題のため、開発工程の終盤においては対処が難しいことが多々あります。
そのような状況において、どのような改善手段があるのか、Oracleを例に解説します。
The document discusses Amazon Aurora, a relational database engine that is compatible with MySQL and PostgreSQL. Aurora is designed to be more scalable, fault tolerant, and efficient than traditional relational databases. It achieves this by utilizing a distributed, self-healing architecture with independent scaling of storage and compute. Aurora also offers improved performance, security, compatibility with MySQL applications, and integration with other AWS services.
The document discusses Amazon Web Services (AWS) Batch and how it can help customers run batch computing workloads on AWS. It notes that AWS Batch automatically provisions the optimal quantity and type of compute resources (e.g., EC2 instances) required to run jobs efficiently. It also allows customers to integrate their own scheduling and application code with AWS Batch through simple API calls or SDKs.
2017/9/7 db tech showcase Tokyo 2017(JPOUG in 15 minutes)にて発表した内容です。
SQL大量発行に伴う処理遅延は、ミッションクリティカルシステムでありがちな性能問題のひとつです。
SQLをまとめて発行したり、処理の多重度を上げることができれば高速化可能です。ですが???
AP設計に起因する性能問題のため、開発工程の終盤においては対処が難しいことが多々あります。
そのような状況において、どのような改善手段があるのか、Oracleを例に解説します。
The document discusses Amazon Aurora, a relational database engine that is compatible with MySQL and PostgreSQL. Aurora is designed to be more scalable, fault tolerant, and efficient than traditional relational databases. It achieves this by utilizing a distributed, self-healing architecture with independent scaling of storage and compute. Aurora also offers improved performance, security, compatibility with MySQL applications, and integration with other AWS services.
The document discusses Amazon Web Services (AWS) Batch and how it can help customers run batch computing workloads on AWS. It notes that AWS Batch automatically provisions the optimal quantity and type of compute resources (e.g., EC2 instances) required to run jobs efficiently. It also allows customers to integrate their own scheduling and application code with AWS Batch through simple API calls or SDKs.
PostgreSQL 14 Beta 1 New Features with Examples (English)Noriyoshi Shinoda
?
This document provides an overview of the major new features in PostgreSQL 14 Beta 1. Some key points include:
- Performance improvements through enhancements to logical replication, parallel queries, LZ4 compression, and BRIN indexes.
- Reliability improvements such as more robust data structure checking and removing password length restrictions.
- Improved maintainability through features like enhanced REINDEX and new monitoring capabilities.
- Preparation for future features like data access by subscripts and changes to functions and operators to support this.
- Incompatibilities include changes to functions, regular expressions, and transaction ID wraparound thresholds.
PostgreSQL 12 New Features with Examples (English) GANoriyoshi Shinoda
?
This document provides an overview of new features in PostgreSQL 12, including improvements to analytic query performance, reliability, and maintainability. It also discusses changes that may cause incompatibility with previous versions. The document is intended for PostgreSQL users and provides detailed information on changes to architecture, SQL statements, configuration parameters, utilities, and contrib modules in PostgreSQL 12.
PostgreSQL 12 Beta 1 New Features with Examples (English)Noriyoshi Shinoda
?
The document summarizes new features in PostgreSQL 12 Beta 1. Major changes include improvements to analytic query performance through enhancements to parallel queries and partition tables, increased reliability with expanded integrity checking tools, and improved maintainability through changes like abolishing the recovery.conf file and adding monitoring features. The document also notes some incompatible changes in PostgreSQL 12.
This document provides an overview and details of new features in PostgreSQL 11. It introduces enhancements to parallel queries, partitioned tables, logical replication, architecture changes, new SQL statements and functions, changes to PL/pgSQL, configuration parameters, and utilities. Major new features include improved performance for analytic queries, maintenance tasks, and reliability.
PostgreSQL 11 New Features English version (Beta 1)Noriyoshi Shinoda
?
PostgreSQL 11 includes enhancements that allow parallel execution for more query types including hash joins, appends, CREATE TABLE AS SELECT statements, and CREATE MATERIALIZED VIEW statements. It also includes improvements to partitioned tables, logical replication, and maintenance features to improve performance, manageability and reliability compared to PostgreSQL 10. Some changes in PostgreSQL 11 can cause incompatibilities with applications, and functions like TO_NUMBER now behave differently than in previous versions.
This document provides an overview of new features in PostgreSQL 10, including native partition tables, logical replication, enhancements to parallel query, monitoring, row level security, SQL statements, and configuration parameters. It discusses features such as partition tables that can improve performance for large datasets, logical replication for reliability, and monitoring changes like the EXPLAIN SUMMARY statement. The document is intended for PostgreSQL users and provides details on the new features and their usage.
PostgreSQL Internals (1) for PostgreSQL 9.6 (English)Noriyoshi Shinoda
?
This document provides an overview of PostgreSQL internals including its process and memory architecture, storage architecture, and file formats. It discusses topics like processes and signals, shared buffers, huge pages, checkpoints, WAL logs, the database directory structure, tablespaces, visibility maps, VACUUM behavior, online backups, and key configuration files. The document is intended for engineers using PostgreSQL and aims to help them better understand its internal workings.
13. Babelfish の非互換部分
トランザクション分離レベル
– トランザクション分離レベルは PostgreSQL と同じ
– 対応していない分離レベルを指定してもエラーにはならない
12
LEVEL SQL Server PostgreSQL Babelfish
READ UNCOMMITED YES NO NO
READ COMMITTED YES YES YES
REPEATABLE READ YES YES YES
SNAPSHOT YES NO NO
SERIALIZABLE YES YES YES
14. Babelfish の非互換部分
トランザクション分離レベル
– 以下の例は READ COMMITTED として動作する
13
1> BEGIN TRANSACTION;
2> SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
3> SELECT * FROM data1 WHERE c1=100;
4> GO
c1 c2
-------------------- -------------
100 before update
(1 rows affected)
1> BEGIN TRANSACTION;
2> UPDATE data1 SET c2='after updated' WHERE c1=100;
3> GO
15. Babelfish の非互換部分
更新と検索の同時実行
– SQL Server では更新中のタプルに対する検索(SELECT)処理はトランザクションの確定まで待機
– データベース属性 allow_snapshot_isolation と read_committed_snapshot を on に変更することで、
PostgreSQL と同様の動作になる
– Babelfish では上記設定が有効になった状態で提供されている(変更不可)
14
1> SELECT snapshot_isolation_state_desc, is_read_committed_snapshot_on FROM sys.databases
WHERE name='master';
2> GO
snapshot_isolation_state_desc is_read_committed_snapshot_on
------------------------------- -----------------------------
ON 1
(1 rows affected)
16. Babelfish の非互換部分
文字列型と Collation
– Collation に日本語サポートが無い
15
– char / varchar / text 型に日本語を格納できない
1> SELECT name FROM sys.fn_helpcollations() WHERE name LIKE '%japan%';
2> GO
name
-----------------------------------
(0 rows affected)
1> CREATE TABLE encode1(c1 varchar(10), c2 nvarchar(10));
2> INSERT INTO encode1 VALUES ('漢字', N'漢字');
3> SELECT * FROM encode1;
4> GO
(1 rows affected)
c1 c2
---------- ----------
?? 漢字
17. Babelfish の非互換部分
シーケンス
– シーケンスの開始番号は PostgreSQL と同じ
– SQL Server では START WITH を省略した場合の開始番号はデータ型の最小値
– NEXT VALUE FOR 構文はサポートされない(NEXTVAL 関数を使う)
16
1> CREATE SEQUENCE seq1 START WITH 1;
2> SELECT NEXT VALUE FOR seq1;
3> GO
Msg 33557097, Level 16, State 1, Server BABELFISH, Line 1
'NEXT VALUE FOR' is not currently supported in Babelfish
1> SELECT NEXTVAL('seq1');
2> GO
– CREATE SEQUENCE 文、ALTER SEQUENCE 文は互換性あり
18. Babelfish の非互換部分
シノニム
17
– シノニムはサポートされていない
1> CREATE SYNONYM syn1 FOR dbo.table1;
2> GO
Msg 33557097, Level 16, State 1, Server BABELFISH, Line 1
'CREATE SYNONYM' is not currently supported in Babelfish
19. Babelfish の非互換部分
MERGE 文
– MERGE 文はサポートされない
18
1> MERGE dbo.Country2 AS C2
2> USING dbo.Country1 AS C1
3> ON C2.ID = C1.ID
4> WHEN MATCHED
5> THEN UPDATE SET C2.Country = C1.Country, C2.City = C1.City
6> WHEN NOT MATCHED BY TARGET
7> THEN INSERT (ID, Country, City) VALUES (C1.ID, C1.Country, C1.City)
8> WHEN NOT MATCHED BY SOURCE
9> THEN DELETE;
10> GO
Msg 33557097, Level 16, State 1, Server BABELFISH, Line 1
'MERGE' is not currently supported in Babelfish
20. Babelfish の非互換部分
DEFERRABLE 制約
– CASE 句による主キー入れ替え
– 正常に動作させるためには PostgreSQL では制約に DEFERRABLE 句が必要
19
1> CREATE TABLE table1(c1 NUMERIC PRIMARY KEY);
2> INSERT INTO table1 VALUES (1);
3> INSERT INTO table1 VALUES (2);
4> UPDATE table1 SET c1 = CASE c1 WHEN 1 THEN 2 WHEN 2 THEN 1 END;
5> GO
(1 rows affected)
(1 rows affected)
Msg 2627, Level 14, State 1, Server BABELFISH, Line 4
duplicate key value violates unique constraint "table1_pkey"
21. Babelfish の非互換部分
カーソル
– 無視されるカーソル属性
– FAST_FORWARD, FOR UPDATE
– エラーになるカーソル属性
– SCROLL, GLOBAL, KEYSET, DYNAMIC, SCROLL_LOCKS, OPTIMISTIC, TYPE_WARNING
– マニュアル上はサポートされないとされているが動作しているように見える構文
– FETCH PRIOR, FETCH FIRST, FETCH LAST, FETCH ABSOLUTE, FETCH RELATIVE
20
1> DECLARE cursor1 CURSOR DYNAMIC FOR SELECT c2 FROM data1;
2> GO
Msg 33557097, Level 16, State 1, Server BABELFISH, Line 1
'DYNAMIC CURSOR' is not currently supported in Babelfish
24. Babelfish の互換性
トランザクション内エラー処理の互換性
– SQL Server ではトランザクション内でエラーが発生しても部分コミット可能
– Babelfish でも同様、DDL がロールバックできる点は元々同じ
23
1> BEGIN TRANSACTION;
2> INSERT INTO data1 VALUES (100, 'normal data');
3> INSERT INTO data1 VALUES (100, 'duplicate data');
4> COMMIT;
5> SELECT * FROM data1;
6> GO
Msg 2627, Level 14, State 1, Server BABELFISH, Line 3
duplicate key value violates unique constraint "data1_pkey"
c1 c2
-------------------- -----------
100 normal data
(1 rows affected)
25. Babelfish の互換性
トランザクションと時刻の互換性
– CURRENT_TIMESTAMP 関数は OS 時刻を返す(≠ トランザクション開始時刻)
– PostgreSQL の NOW 関数も使えるが、こちらはトランザクション間は同一時刻を返す
24
1> BEGIN TRANSACTION;
2> SELECT CURRENT_TIMESTAMP, NOW();
3> GO
current_timestamp now
----------------------- -----------------------------
2022-02-10 18:58:06.527 2022-02-10 22:34.28.024456+09
1> SELECT CURRENT_TIMESTAMP, NOW();
2> GO
current_timestamp now
----------------------- -----------------------------
2022-02-10 19:01:06.210 2022-02-10 22:34.28.024456+09
26. Babelfish の互換性
データ型の互換性
– 非互換があるデータ型は独自に作成されている
25
SQL Server Babelfish 備考
char / varchar / text sys.bpchar / sys.varchar / text text は同一
nchar / nvarchar / ntext sys.nchar / sys.nvarchar / sys.ntext
bit / decimal / money /
smallmoney / tinyint / bigint /
integer / smallint / tinyint / real /
float
sys.bit / sys.decimal / sys.money /
sys.smallmoney / bigint / integer /
smallint / sys.tinyint / real / double
bigint, integer, numeric, smallint,
real は同一。float は double にマッ
プ
date / time / datetime2 /
datetime / datetimeoffset
date / time without time zone /
sys.datetime2 / sys.datetime /
sys.datetimeoffset
date は同一
binary / varbinary / image sys.binary / sys.varbinary /
sys.image
27. Babelfish の互換性
特殊な構文の互換性
26
– テーブル作成構文
– SELECT文の結果からテーブルを作成する構文
SQL Server/Bablefish PostgreSQL
?実テーブル
1> SELECT * INTO data2 FROM data1;
2> GO
?一時テーブル
1> SELECT * INTO #temp1 FROM data1;
2> GO
?実テーブル
postgres=> CREATE TABLE data2 AS SELECT * FROM data1;
SELECT 1000
?一時テーブル
postgres=> CREATE TEMPORARY TABLE temp1 AS SELLECT *
FROM data1;
SELECT 1000
28. Babelfish の互換性
特殊な構文の互換性
– かなり特殊な構文もサポートされている(その通りの動作にはならない場合あり)
27
?列名のエイリアス
> SELECT alias1=count(*) FROM data1;
?WITH 句(テーブルオプション)
> SELECT * FROM data1 WITH (READUNCOMMITTED) WHERE c1=100;
?OPTION 句と結合方法(ヒント)
> SELECT count(*) FROM data1 INNER HASH JOIN data2 ON data1.c1=data2.c1
OPTION (FORCE ORDER);
?先頭行
> SELECT TOP 10 * FROM data1 ORDER BY 1;
?ROW_NUMBER OVER 関数
> SELECT c1 FROM (SELECT c1,ROW_NUMBER() OVER (ORDER BY c1) AS rownum FROM data1) AS t
WHERE rownum BETWEEN 101 AND 200 ORDER BY rownum;
29. Babelfish の互換性
ORDER BY 句の互換性
– SQL Server では NULL は昇順 ORDER BY で最小扱い
– NULLS FIRST / NULLS LAST 句は存在しない
SQL Server/Bablefish PostgreSQL
28
1> SELECT * FROM data1 ORDER BY c2;
2> GO
c1 c2
----------- ----------
0 NULL
100 data1
200 data2
(3 rows affected)
postgres=> SELECT * FROM data1 ORDER BY c2;
c1 | c2
-----+-------
100 | data1
200 | data2
0 | null
(3 rows)
30. Babelfish の互換性
演算子の互換性
– 文字列の連結演算子
SQL Server/Bablefish PostgreSQL
29
1> SELECT '123' + 456 plus1;
2> GO
plus1
-----------
579
(1 rows affected)
1> SELECT '123' + '456' plus1;
2> GO
plus1
------
123456
(1 rows affected)
postgres=> SELECT '123' + 456 plus1;
plus1
-------
579
(1 row)
postgres=> SELECT '123' + '456' plus1;
ERROR: operator is not unique: unknown + unknown
LINE 1: SELECT '123' + '456' plus1;
^
HINT: Could not choose a best candidate operator. You
might need to add explicit type casts.
31. Babelfish の互換性
ストアド?プロシージャ
– SQL Server/Babelfish PostgreSQL (PL/pgSQL)
30
CREATE FUNCTION dbo.ufnGetInventoryStock
(@ProductID INT) RETURNS INT AS
BEGIN
DECLARE @ret INT;
SELECT @ret = SUM(p.Quantity)
FROM Production.ProductInventory p
WHERE p.ProductID = @ProductID
AND p.LocationID = '6';
IF (@ret IS NULL)
SET @ret = 0;
RETURN @ret;
END;
CREATE FUNCTION dbo.ufnGetInventoryStock
(_ProductID INT) RETURNS INT AS $$
DECLARE ret INT;
BEGIN
SELECT INTO ret SUM(p.Quantity)
FROM Production.ProductInventory p
WHERE p.ProductID = _ProductID
AND p.LocationID = '6';
IF ret IS NULL THEN
ret := 0;
END IF;
RETURN ret;
END; $$ LANGUAGE plpgsql;