都内で働くSEの技術的なひとりごと / Technical soliloquy of System Engineer working in Tokyo

都内でサラリーマンやってます。SQL Server を中心とした (2023年からは Azure も。) マイクロソフト系(たまに、OSS系などマイクロソフト以外の技術も...)の技術的なことについて書いています。日々の仕事の中で、気になったことを技術要素関係なく気まぐれに選んでいるので記事内容は開発言語、インフラ等ばらばらです。なお、当ブログで発信、発言は私個人のものであり、所属する組織、企業、団体等とは何のかかわりもございません。ブログの内容もきちんと検証して使用してください。英語の勉強のため、英語の

Creators Update でいいなぁと思った機能を挙げてみる

 Windows 10 の Creators Update が4月11日( 日本では、4月12日 )リリースされました。まだあまり触ってないのですが、お気に入りの機能を二点挙げてみます。まず一つ目は夜間モード。液晶の色彩をコントロールしてくれます。若干暗めの部屋などで重宝しそうです。『設定』→『ディスプレイ』の夜間モードで設定することができます。
f:id:koogucc11:20170412074820p:plain

 暗いところだと暖色のディスプレイは目に優しいので、おじさんの自分にはいい機能ですww
f:id:koogucc11:20170412074824p:plain

 二つ目は携帯電話による Windows のロック機能です。Bluetooth でペアリングしたデバイスと PC が一定距離離れたら自動的に PC をロックしてくれます。
f:id:koogucc11:20170412074753p:plain

 しかし、ロックするまでの時間が1分間とかなり長いのと、結構 PC から離れないといけないところが残念かもです。このあたりの閾値を調整できるといいですね。
windows 10 で動的ロックを使用する方法 - Bing
f:id:koogucc11:20170412075631p:plain

 もうすぐ de:code。
ryuchan.hatenablog.com

 今日は金沢出張、久しぶりの金沢で美味しい寿司♪
akamesushi.com

 寿司図鑑。

すし図鑑

すし図鑑


 

日曜日のお昼から仕事しようと思ったけど、何か気が乗らないのでネットみてたら、Cumulative Update 2 for SQL Server 2016 SP1 がリリースされていたのでちょっとお試ししてみる

 SQL Server 2016 SP1 CU2 がリリースされていました。
https://support.microsoft.com/en-us/help/4013106/cumulative-update-2-for-sql-server-2016-sp1

 sys.dm_db_stats_histogram が DMV に追加されたようです。
ryuchan.hatenablog.com

 SQL Server 2016 SP1 CU2 の環境で下記のクエリを実行してみましょう。

SELECT
    s.*,
    sh.*
FROM 
    sys.stats s
    CROSS APPLY sys.dm_db_stats_histogram(s.object_id,s.stats_id) sh

f:id:koogucc11:20170326142506p:plain

f:id:koogucc11:20170326142515p:plain

 何かいいサンプル作りたいなぁと思いましたが、面倒なので ( 子供の面倒と仕事がある... ) MSSQL Tiger Team のブログに非常に良いサンプルがありました。早速見てみましょう。
blogs.msdn.microsoft.com

 はい、本当にそう思います。まわりにそんな人いたらいいんですが....

Statistics being the building blocks on which the Query Optimizer reasons to compile a good enough plan to resolve queries, it’s very common that anyone doing query performance troubleshooting needs to use DBCC SHOW_STATISTICS to understand how statistics are being used, and how accurately they represent data distribution.

 それを見ようとする人もなかなかいませんが...

Let’s say you wanted to understand where the estimation came from, then naturally you will want to look for whatever stats object references that single column (using a single column predicate for simplicity sake). If you need to programmatically access this data, then usually you would dump DBCC SHOW_STATISTICS … WITH HISTOGRAM to a table, and then use it from there. That is not ideal.

 そして、今回 CU2 で dm_db_stats_histogram が追加されました。

With the latest release of SQL Server 2016 SP1 CU2, we added a new Dynamic Management Function (DMF) sys.dm_db_stats_histogram, which is similar to running the above DBCC statement. Note: this DMF is also available in SQL Server vNext CTP 1.3.

 DBCC SHOW_STATISTICS … WITH STATS_HEADER を sys.dm_db_stats_properties で参照することができます。

This further completes the story we started with sys.dm_db_stats_properties, which has a similar output to running DBCC SHOW_STATISTICS … WITH STATS_HEADER.

 ここが肝です。指定された述語から統計情報を用いて算出された推定行数を求めることができます。

But to make it more interesting, here’s one example on how you can leverage these DMFs inline, to get information on which stat and respective histogram steps cover my predicate, in the scope of my table and column:

SELECT
    ss.name,
    ss.stats_id,
    shr.steps,
    shr.rows,
    shr.rows_sampled,
    shr.modification_counter,
    shr.last_updated,
    SUM(sh.range_rows + sh.equal_rows) AS predicate_step_rows
FROM
    sys.stats ss
    INNER JOIN
        sys.stats_columns sc
    ON  ss.stats_id = sc.stats_id
    AND ss.object_id = sc.object_id
    INNER JOIN
        sys.all_columns ac
    ON  ac.column_id = sc.column_id
    AND ac.object_id = sc.object_id CROSS APPLY sys.dm_db_stats_properties(ss.object_id, ss.stats_id) shr CROSS APPLY sys.dm_db_stats_histogram(ss.object_id, ss.stats_id) sh
WHERE
    ss.[object_id] = OBJECT_ID('FactResellerSales')
AND ac.name = 'OrderDate'
AND sh.range_high_key BETWEEN CAST('20110101' AS DATE) AND CAST('20110606' AS DATE)
GROUP BY
    ss.name,
    ss.stats_id,
    shr.steps,
    shr.rows,
    shr.rows_sampled,
    shr.modification_counter,
    shr.last_updated

 このあたりを拡張して、統計情報に関するクエリを作成できそうです。さて、子供と少しだけお出かけして、仕事でもするか....

やる気のスイッチ! (Sanctuary books)

やる気のスイッチ! (Sanctuary books)

SQL Server next version CTP 1.4 now available なので、少し内容をみてみる

 CTP 1.4 がリリースされていましたね。
blogs.technet.microsoft.com

 内容を見てみましょう。
https://msdn.microsoft.com/en-US/library/mt788653(SQL.130).aspx

 LinuxSQL Agent サービスとバグフィックスだけのようです。

  • SQL Server Database Engine
    • There are no new Database Engine features in this CTP.
    • This CTP contains bug fixes for the Database Engine.
    • For a detailed list of vNext CTP enhancements in previous CTP releases, see What's New in SQL Server vNext (Database Engine).
  • SQL Server R Services
    • There are no new R Services features in this CTP.
    • For more detailed R Services what's new information, including details from previous CTPs, see What's New in SQL Server R Services.
  • SQL Server Reporting Services (SSRS)
    • There are no new SSRS features in this CTP.
    • For more detailed SSRS what's new information, including details from previous releases, see What's new in Reporting Services.
  • SQL Server Analysis Services (SSAS)
    • There are no new SSAS features in this CTP.
    • For more details, including what's new for Analysis Services in the latest preview releases of SSDT and SSMS, see What's New in Analysis Services vNext.
  • SQL Server Integration Services (SSIS)
    • There are no new SSIS features in this CTP.
    • For more detailed SSIS what's new information, including details from previous CTPs, see What's New in Integration Services vNext.
  • Master Data Services (MDS)
    • There are no new Master Data Services features in this CTP.

 最近、肉好き。

ステーキ本 (別冊Lightning Vol. 163) (エイムック 3640 別冊Lightning vol. 163)

ステーキ本 (別冊Lightning Vol. 163) (エイムック 3640 別冊Lightning vol. 163)

時間をおくだけで、どんどんおいしくなる 熟成レシピ

時間をおくだけで、どんどんおいしくなる 熟成レシピ

 ここ行ってみたい。

肉屋 格之進F

食べログ 肉屋 格之進F

de:code 2017 のスケジュールが決定していたので晒してみる

de:code (decode) 2017 | 日本マイクロソフトの開発者/アーキテクト/IT Pro 向けイベント - Microsoft Events & Seminars
f:id:koogucc11:20170308211709p:plain

 de:code 2017 のスケジュールです。今年はどんな内容になるんだろう。

 11/14 に発売?

Mastering Visual Studio 2017

Mastering Visual Studio 2017

 11/15 ?

Professional Visual Studio 2017

Professional Visual Studio 2017

ブログはじめて 4 年たったので、記念投稿してみる

 1,2,3,4年目は記念投稿していなかったので、5年目は記念投稿してみます。最初投稿はやっぱひどいですね。
ryuchan.hatenablog.com

さて、ブログなるものをはじめようとおもうのだが...

何を書いていいものやら....

とりあえずは、技術的なことの備忘録的に使ってみようか..

ひとりごとに使ってみようか...

 さて、どこまで続けられるのか....

継続は力なり―人生を本音で生きた女校長の記録

継続は力なり―人生を本音で生きた女校長の記録

あとで USE HINT の件は調査するので、メモしておいてみる

 ちょっと真面目に調査しなければいけないとふと思ったので、メモしておきます。
blogs.msdn.microsoft.com

New USE HINT query option – A new query option, OPTION(USE HINT(‘

 
 USE HINT に関してちゃんと調査するって書いてたのに。
ryuchan.hatenablog.com

クエリヒントが追加されています。開発者視点ていうと HINT 句 だけでいいのは敷居が下がった感じでいいですね。これはあとで試してみよう。

SQL Server 2016 SP1 がリリースされたので、ちょっとみてみる - 都内で働くSEの技術的なひとりごと

 sysadmin 権限が必要な QUERYTRACEON ではなく、USE HINT で指定できるようになったのは大きいですね。過去に QUERYTRACEON に触れています。
ryuchan.hatenablog.com

 USE HINT に指定できるものは、下記のクエリを実行することで知ることができます。

SELECt
    *
FROM 
    sys.dm_exec_valid_use_hints

f:id:koogucc11:20170219235539p:plain

 以上、メモでした。

新潟で食とお酒ちゃんと楽しみたいなぁ。

まっぷる 新潟 佐渡 '17 (まっぷるマガジン)

まっぷる 新潟 佐渡 '17 (まっぷるマガジン)

月刊新潟KOMACHI 3月号(新潟版)

月刊新潟KOMACHI 3月号(新潟版)

新潟本 (エイムック 3228)

新潟本 (エイムック 3228)

新潟酒本

新潟酒本

新潟酒場案内

新潟酒場案内