DB

SQLチューニング(パーティションワイズ結合)

DB

hashパーティションパーティション数=10100万件と1000万件のテーブルを作成 MySQL (8.0.29) drop table tab1;create table tab1(col1 int)partition by hash(col1)(partition p00, partition p01, partition p02, partition p03, partition p04, partition p…

Dockerで各種DBを作成する

DB

MySQL (8.0.23)https://qiita.com/TAMIYAN/items/ed9ec892d91e5af962c6https://note.com/shift_tech/n/nd5765c9f1c26 OS: Ubuntu 20.04 -- 1. イメージを取得 docker image pull mysql:8.0.23docker image ls -- 2. イメージをコンテナ化 docker container r…

CSV出力時とDB格納時のサイズ比較

DB

CSV出力時とDB格納時のサイズはおよそ同じ MySQL (8.0.29) -- 1. テストデータ作成 drop table tab1;create table tab1( col1 int primary key ,col2 bigint ,col3 datetime ,col4 varchar(100) ); drop procedure proc1; delimiter //create procedure proc…

AES暗号化

DB

MySQL (8.0.29)https://gihyo.jp/dev/serial/01/mysql-road-construction-news/0174 https://qiita.com/mhagita/items/899483f08347fddd9567 SET block_encryption_mode = 'aes-256-cbc'; select @@block_encryption_mode; 暗号化 select HEX(AES_ENCRYPT('…

ユーザ名、スキーマ名の変更

DB

MySQL (8.0.29)https://www.dbonline.jp/mysql/user/index3.html select user,host from mysql.user; rename user user1@'%' to user2@'%'; Oracle (19c) コマンドでの実行は不可 expdp test/test@pdb1 directory=ORA_DIR dumpfile=a.dmp logfile=a.log sche…

インラインビューの更新

DB

MySQL、PostgreSQL、SQL Serverはインラインビューの更新不可 MySQL (8.0.29) drop table tab1;create table tab1( col1 bigint primary key ,col2 bigint ); drop table tab2;create table tab2( col1 bigint primary key ,col2 bigint ); drop procedure p…

エクスポート/インポート、バックアップ/リストアのドライランオプション

DB

MySQL (8.0.29) mysqldumpにドライランオプションはない模様 Oracle (19c) expdpにはESTIMATE_ONLYオプションありimpdpにはESTIMATE_ONLYオプション無しRMANのbakupやrestoreにvalidateオプションはある expdp test/test@pdb1 directory=ORA_DIR logfile=a.l…

抽出条件付きインポート

DB

MySQL (8.0.29) 調べた限り、load data ステートメントで抽出条件は指定できない模様 Oracle (19c) ※抽出条件として、他テーブル参照の場合、ダンプファイル内のテーブルとインポート先DBのテーブルのどちらを参照しているかを確認する 結論:queryパラメー…

データ更新時のundo使用量(更新カラム数の影響)

DB

MySQL (8.0.28) -- 1. テストテーブル準備drop table tab1;create table tab1( col1 int primary key ,col2 char(100) ,col3 char(100) ,col4 char(100) ,col5 char(100) ,col6 char(100) ,col7 char(100) ,col8 char(100) ,col9 char(100) ); drop procedur…

データ更新時のundo使用量(インデックスの影響)

DB

MySQL (8.0.28) -- 1. テストテーブル準備drop table tab1;create table tab1( col1 int primary key ,col2 char(100) ,col3 char(100) ); drop procedure proc1; delimiter //create procedure proc1(in x int)begin declare i int; set i = 0; start trans…

リストパーティションのメンテナンス

DB

MySQL (8.0.28) drop table tab1; create table tab1( col1 int not null, col2 varchar(10) not null) partition by list columns ( col2 ) ( partition p1 values in ('AX','AY') , partition p2 values in ('BX','BY') , partition p3 values in ('CX','C…

インポートに必要な権限

DB

MySQL (8.0.28) 結論: ・対象テーブルのdrop権限・対象テーブルのcreate権限・対象テーブルのalter権限・対象テーブルのinsert権限・対象テーブルのselect権限・対象データベースのlock tables権限 -- 動作確認 drop user 'user1'@'%';create user 'user1'@…

エクスポートに必要な権限

DB

MySQL (8.0.28) 結論: ・対象テーブルのselect権限・process権限・対象データベースのlock tables権限 -- 動作確認 drop user 'user1'@'%';create user 'user1'@'%' identified by 'user1'; drop table tab1;create table tab1(col1 int);insert into tab1 …

ブルームフィルタ

DB

MySQL (8.0.28) 調べた限り、サポートしていない模様 Oracle (19c) https://www.ex-em.co.jp/blog/oraclegijutsujoho12/ HJとMJでサポートされている前提条件複数あり結合前に件数をあらかじめ減らすことで結合負荷を減少させる select * from V$SQL_JOIN_FI…

ハッシュパーティションのメンテナンス

DB

MySQL (8.0.26) drop table tab1; create table tab1( col1 bigint not null, col2 bigint not null) partition by hash ( col2 ) ( partition p1 , partition p2 , partition p3 , partition p4 , partition p5 , partition p6 , partition p7 , partition …

ワークロード再生

DB

MySQL (8.0.28)https://mita2db.hateblo.jp/entry/2020/08/30/193650https://github.com/Percona-Lab/query-playback Percona Playback ソースDB: mmm066ターゲットDB: mmm128 -- 1. Percona Playbackインストール[mmm128で実行] git clone https://github.c…

スケジューラジョブ実行

DB

MySQL (8.0.26)https://qiita.com/magaming/items/6a941ef1c2f673de8ae7 drop procedure proc1; delimiter //create procedure proc1(in p1 int)begin start transaction; update tab1 set col1 = p1; commit;end//delimiter ; select @@event_scheduler; cr…

システム統計

DB

MySQL (8.0.26) 調べた限りなし Oracle (19c)https://docs.oracle.com/cd/F19136_01/tgsql/gathering-optimizer-statistics.html#GUID-AC23D691-5C54-4EF9-BF9F-65121F2AFC31 システム統計の手動収集を検討する場合Oracle Exadataを使用し、かつ、データベー…

Embulk

DB

MySQL (8.0.26)https://qiita.com/777nancy/items/d5512bffab50a0796c5c 前提: Embulkインストール済 wget https://download.oracle.com/otn-pub/otn_software/jdbc/1914/ojdbc8-full.tar.gztar xvzf ojdbc8-full.tar.gzwget https://jdbc.postgresql.org/do…

実行計画へのメモリサイズの影響

DB

SQL Server以外はメモリサイズで実行計画が変化する可能性がある MySQL (8.0.26) innodb_buffer_pool_sizeとjoin_buffer_sizeとを変更し、オプティマイザトレースを比較する -- 1. テストデータ作成 drop table tab1;create table tab1( col1 bigint ,col2 b…

SQLチューニング(delete文のwhere条件に更新テーブル追加)

DB

MySQL (8.0.26) drop table tab1;create table tab1( col1 bigint ,col2 bigint ); drop table tab2;create table tab2( col1 bigint ,col2 bigint ); drop table tab3;create table tab3( col1 bigint ,col2 bigint ); drop procedure proc1; delimiter //c…

SQLチューニング(共通部分切り出し)

DB

with句での切り出しについては実行計画変化なし(MySQL,SQL Server)あまり効果なし(Oracle)逆に悪化(PostgreSQL) MySQL (8.0.26) drop table tab1;create table tab1( col1 bigint ,col2 varchar(1000) ,col3 varchar(1000) ,col4 varchar(1000) ,col5 varcha…

索引結合スキャン

DB

MySQL (8.0.26)https://dev.mysql.com/doc/refman/8.0/ja/index-merge-optimization.html#index-merge-intersection drop table tab1;create table tab1( col1 bigint ,col2 bigint ,col3 bigint ,col4 varchar(1000) ,col5 varchar(1000) ,col6 varchar(100…

自動SQLチューニング

DB

MySQL (8.0.26) 調べた限りなし Oracle (19c) https://docs.oracle.com/cd/F19136_01/tgsql/sql-tuning-advisor.html#GUID-87D3AA10-60CE-4F5B-879B-B2E851874B83 自動SQLチューニング 自動実装が有効になっている場合、アドバイザはSQLプロファイルを作成す…

SQLチューニング(update文のwhere条件に更新テーブル追加)

DB

MySQL (8.0.26) drop table tab1;create table tab1( col1 bigint ,col2 bigint ); drop table tab2;create table tab2( col1 bigint ,col2 bigint ); drop table tab3;create table tab3( col1 bigint ,col2 bigint ); drop procedure proc1; delimiter //c…

SQLチューニング(ビューマージの抑止)

DB

MySQL (8.0.26) drop table tab1;create table tab1( col1 bigint ); drop table tab2;create table tab2( col1 bigint ); drop table tab3;create table tab3( col1 bigint ); drop table tab4;create table tab4( col1 bigint ); drop procedure proc1; de…

HJ/NLの切替件数確認

DB

MySQL (8.0.26) 処理対象件数が下記パターンで(1千,1千)(1万,1万)(10万,10万)(100万,100万) HJ = Hash join(Full Scan/Full Scan)NL = Nested loop(Full Scan/Index Lookup)を比較 drop table tab1;create table tab1( col1 bigint ,col2 bigint ); drop tab…

where条件の推移律

DB

MySQL (8.0.26) drop table tab1;create table tab1( col1 bigint ,col2 bigint ); drop table tab2;create table tab2( col1 bigint ,col2 bigint ); drop table tab3;create table tab3( col1 bigint ,col2 bigint ); drop procedure proc1; delimiter //c…

HJ結合順へのデータ件数影響

DB

MySQL (8.0.26) drop table tab1;create table tab1( col1 bigint ,col2 bigint ); drop table tab2;create table tab2( col1 bigint ,col2 bigint ); drop table tab3;create table tab3( col1 bigint ,col2 bigint ); drop procedure proc1; delimiter //c…

結合条件の推移律

DB

Oracleのみ結合条件の推移律未対応 MySQL (8.0.26) drop table tab1;create table tab1( col1 bigint ,col2 bigint ); drop table tab2;create table tab2( col1 bigint ,col2 bigint ); drop table tab3;create table tab3( col1 bigint ,col2 bigint ); dr…