Lazy Diary @ Hatena Blog

PowerShell / Java / miscellaneous things about software development, Tips & Gochas. CC BY-SA 4.0/Apache License 2.0

常用漢字表を新旧漢字変換の根拠資料に使う場合の制約

文化庁の出している常用漢字表 *1 には康煕字典体と常用漢字の対応が記載されている。ただ詳しく調べてみたら、対応の記載自体に以下のようなコーナーケースがあるみたい。

  • 「著しい差異のないものは省」かれているので「頬⇄頰」のような対応は記載がない。
  • 康熙字典体と常用漢字が一対一対応しない場合に、記載のないケースが見受けられる。たとえば「辺⇄邊」はあっても「辺⇄邉」はない、「闘⇄鬭」はあっても「闘⇄鬪」はない。
  • 当用漢字表常用漢字表で字体が変わったものは記載がない。たとえば「礼⇄禮」はあっても「礼⇄礼」はない。

ほかにも、出典が常用漢字表なので、新字が常用漢字でないものは記載がない。たとえば「鴈⇄雁」はないし、「禎⇄禎」もない *2 。 新字・旧字の変換に使おうと思ったら、常用漢字表自体を全数として処理する場合以外は注意が必要そう。

You cannot set CPU affinity of PostgreSQL instance started through pg_ctl with Start-Process and Process.ProcessorAffinity

Background:

In Windows, you can set the CPU affinity of an user process with Start-Process PowerShell cmdlet and System.Diagnostics.Process.ProcessorAffinity property like this:

$app = Start-Process -FilePath C:\Windows\System32\mspaint.exe -PassThru
$app.ProcessorAffinity = 0x3

Problem:

You cannot set CPU affinity of an PostgreSQL instance with Start-Process cmdlet and System.Diagnostics.Process.ProcessorAffinity property, when you start the instance through pg_ctl.

You will get SetValueInvocationException like this:

$app = Start-Process 'c:\path\to\PostgreSQL\12\bin\pg_ctl.exe' 'start -D C:\path\to\PostgreSQL\12\data' -PassThru -NoNewWindow
$app.ProcessorAffinity = 0x3

"ProcessorAffinity" の設定中に例外が発生しました: "プロセス (15860) が終了したため、要求を処理できません。"
発生場所 行:1 文字:1
+ $app.ProcessorAffinity = 0x3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
    + FullyQualifiedErrorId : ExceptionWhenSetting

Cause

In PowerShell, it seems there are no ways to set CPU affinity of an user process when it starts. ProcessorAffinity property sets CPU affinity of an user process through Process object retrieved before it accessed.

In PostgreSQL, pg_ctl command exits immediately after it starts an PostgreSQL instance. If the process is exited before you set ProcessorAffinity, you cannot set CPU affinity.

Solution

You have to use start /affinity command in cmd.exe instead of Start-Process. For example, you can start PostgreSQL instance with CPU affinity from PowerShell like this:

cmd.exe /c "start /affinity 3 /B c:\path\to\PostgreSQL\12\bin\pg_ctl.exe start -w -s -D C:\path\to\PostgreSQL\12\data"

An error in pgbench: invalid command in command "setrandom"

Background:

I tried to run the following transaction script on pgbench contained in PostgreSQL 12:

\set nbranches 1 * :scale
\set ntellers 10 * :scale
\set naccounts 100000 * :scale
\setrandom aid 1 :naccounts
\setrandom bid 1 :nbranches
\setrandom tid 1 :ntellers
\setrandom delta -5000 5000
BEGIN;
UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
END;

This script is equivalent of the TPC-B benchmark embedded in pgbench.

Problem

I got following error when I tried to run the previous script with pgbench command:

> .\pgbench.exe -U postgres -c 10 -t 1000 -f C:\tmp\insert.pgbench test
C:\tmp\insert.pgbench:4: invalid command in command "setrandom"
\setrandom aid 1 :naccounts

Cause

setrandom meta command is not found in the document of PostgreSQL 9.6 *1 or later (the document of PostgreSQL 9.5 has a description *2 ). So it seems obsoleted in PostgreSQL 9.6.

Solution

Use random(min,max) instead of \setrandom. The following script is the equivalent for PostgreSQL 12:

\set nbranches 1 * :scale
\set ntellers 10 * :scale
\set naccounts 100000 * :scale
-- \setrandom aid 1 :naccounts
\set aid random(1,:naccounts)
-- \setrandom bid 1 :nbranches
\set bid random(1,:nbranches)
-- \setrandom tid 1 :ntellers
\set tid random(1,:ntellers)
-- \setrandom delta -5000 5000
\set delta random(-5000,5000)
BEGIN;
UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
END;

HDMI接続の外部モニタで色がおかしい

症状

PCと外部モニタをHDMIで接続した際、写真のように外部モニタの色がおかしくなる。

f:id:satob:20200331023418j:plain
色がおかしい場合の表示(HDMI接続)

  • 黒で表示されるはずの箇所が緑色で、白で表示されるはずの箇所が紫色で表示される。
  • OSDの色は問題なく表示されるので、パネルの異常ではない。

背景

  • Mac mini (Early 2009)でDVI-HDMI接続した際は問題なく表示されていた。
  • モニタの型番は「H40xx」と表示されている。

原因

HDMIのハンドシェイクが上手くいっていない模様。

対策

  • Windowsの[設定]-[ディスプレイ]-[ディスプレイの詳細設定]からディスプレイアダプタのプロパティを表示し、[アダプタ]-[モードの一覧]でリフレッシュレートを強制的に50Hzに設定すると、色が正常になる(ただしデスクトップの端が画面に表示されなくなる)。
  • アナログRGBケーブルでPC-外部モニタ間を接続すると問題なく表示された。

f:id:satob:20200331023450j:plain
正常な表示(RGB接続)

結論としては、アナログRGB最強!(それでいいのか)

一度に扱える情報量を測る指標

PISAとかPIAACでは、ある能力をもとに「できるかできないか」を調べてると思うんだけど、一度に扱える情報量を測る方法ってあるのかな?

たとえば未就学児向けの科学的な読みもの(「こどものとも」とか)の内容に対して、

  • 読めない字はない
  • 一冊二冊なら読んで内容も理解できる
  • 20冊30冊だと内容を理解するのがつらい

というレベルがどの程度のランクにあるか測る方法はないのかな(言語的IQが使えるのかな)?