Out of Memory

本ブログは更新を停止しました。Aerieをよろしくお願いいたします。

目次

Blog 利用状況

ニュース

2009年3月31日
更新を停止しました。引き続きAerieを御愛顧くださいませ。
2009年2月3日
原則としてコメント受付を停止しました。コメントはAerieまでお願いいたします。
詳細は2月3日のエントリをご覧ください。
2008年7月1日
Microsoft MVP for Developer Tools - Visual C++ を再受賞しました。
2008年2月某日
MVPアワードがVisual C++に変更になりました。
2007年10月23日
blogタイトルを変更しました。
2007年7月1日
Microsoft MVP for Windows - SDKを受賞しました!
2007年6月20日
スキル「ニュース欄ハック」を覚えた!
2006年12月14日
記念すべき初エントリ
2006年12月3日
わんくま同盟に加盟しました。

カレンダー

中の人

αετο? / aetos / あえとす

シャノン? 誰それ。

顔写真

埼玉を馬鹿にする奴は俺が許さん。

基本的に知ったかぶり。興味を持った技術に手を出して、ちょっと齧りはするものの、それを応用して何か形にするまでは及ばずに飽きて放り出す人。

書庫

日記カテゴリ

OracleではSelectを止められない?

排他制御とは、1つのリソースに複数のスレッドからアクセスするときに、調停を行うことだ。
教科書的な排他制御の説明はこんな感じだろう。

ある変数に対して、2つのスレッドがインクリメントを試みる。
インクリメントとは、

  1. 変数の現在の値を取得する
  2. それに1を足す
  3. 足した結果を変数に書き戻す

という一連の操作である。
変数の初期値が1であるとして、2つのスレッドが競合すると、

  1. スレッドAが変数から1を読み取る。
  2. スレッドBが変数から1を読み取る。
  3. スレッドAが読み取った値に1を足す
  4. スレッドBが読み取った値に1を足す。
  5. スレッドAが結果を書き戻す。変数の値は2になる。
  6. スレッドBが結果を書き戻す。変数の値は2になる。

となる。
インクリメントが2回行われているから、結果は3にならなければいけないのに、2になってしまう。
これを防ぐために、ロックが使われる。

  1. スレッドAが変数から1を読み取る。
  2. スレッドBが変数を読み取ろうとするが、スレッドAがロックしているため待つ。
  3. スレッドAが読み取った値に1を足す。
  4. スレッドAが結果を書き戻す。変数の値は2になる。
  5. スレッドAがロックを解放する。
  6. スレッドBが動き出し、変数から2を読み取る。
  7. スレッドBが読み取った値に1を足す。
  8. スレッドBが結果を書き戻す。変数の値は3になる。

万事めでたし、というわけだ。

データベースで言うと、変数から読み取る操作がSelect、書き戻す操作がInsertやUpdateになる。
上記の例で言えば、スレッドAがロックをかけたら、スレッドBのSelectも止められなければならない。でなければ、スレッドAが更新した後の値を読み取れないからだ。

だが、どうもOracleには、他人がSelectするのを止める術が無いように思える(Select for Updateなら止められるが、更新がInsertのケースでは使えない)。
SQL Serverでは可能らしいと聞くのだが。

こういう場合、Oracleでは、

  • 同じ行をUpdateするなら、Select for Updateか、タイムスタンプ列を使った楽観的排他制御
  • 新しい行をInsertするなら、該当列に一意性制約をかけておき、成功するまでループ

という方法になるのだろうか。
Insertの際に一意でなければならない列の値をユーザに決定させる場合は、成功するまで何度でもトライアンドエラーさせるしかなさそうだ。

投稿日時 : 2008年3月26日 10:46

Feedback

# re: OracleではSelectを止められない? 2008/03/26 11:03 はつね

Oracleの読み取り一貫性は、ロックをかけて変更しているときは、変更前の値がとれる仕組みですね。INSERTのときはINSERT前=そのレコードがない状態になりますね。

UPDATEのときはSELECT~FOR UPDATE、INSERTのときはINSERT実行時に他が同じPKに対してUPDATE/INSERTしていればそのSQL文またはトランザクションが完了するまでロック解除待ちになります。
※FOR UPDATEにはNO WAITオプションあり

# re: OracleではSelectを止められない? 2008/03/26 11:26 Streetw☆

>・同じ行をUpdateするなら、Select for Updateか、タイムスタンプ列を使った楽観的排他制御

私は楽観的ロックでしてます。
そのときの条件は、読み取ったときの値(+1する前の値)を渡してます。

>・新しい行をInsertするなら、該当列に一意性制約をかけておき、成功するまでループ

insertに失敗したらupdateに切り替えないといけないですね。

それとたいていは、自立型トランザクションにする必要があると思います~

>SQL Serverでは可能らしいと聞くのだが。

マルチバージョニングがなかったころのREAD COMMITTEDの動作の話ですね。
#確か今も互換性のためにデフォルトは同じだったかな。。

# re: OracleではSelectを止められない? 2008/03/26 11:54 シャノン

> INSERTのときはINSERT前=そのレコードがない状態になりますね。
> INSERTのときはINSERT実行時に他が同じPKに対してUPDATE/INSERTしていればそのSQL文またはトランザクションが完了するまでロック解除待ちになります。

ですね。
で、同じ値をInsertしようとすると、ロックが解除された時点で制約違反で例外が飛ぶと。
つまり、「ある値を持ったデータがあるかどうかチェックして、なければInsert」という処理は、ロックを使ったとしても不可能である、ということになりますね。

> 私は楽観的ロックでしてます。
> そのときの条件は、読み取ったときの値(+1する前の値)を渡してます。

それでもいいですね。

> insertに失敗したらupdateに切り替えないといけないですね。

いや、切り替えちゃ駄目なケースを想定してます。
キーがある値であるレコードが存在しなければその値でinsert、あれば別の値に変えてinsertする場合です。

> 自立型トランザクションにする必要があると思います~

また知らん言葉が出てきた。

> マルチバージョニングがなかったころのREAD COMMITTEDの動作の話ですね。

今は SQL Server でも Select は止めないのが普通なんですかね。

# My programmer is trying to convince me to move to .net from PHP. I have always disliked the idea because of the expenses. But he's tryiong none the less. I've been using WordPress on a variety of websites for about a year and am worried about switching t 2019/04/11 4:46 My programmer is trying to convince me to move to

My programmer is trying to convince me to move to .net from PHP.
I have always disliked the idea because of the expenses.
But he's tryiong none the less. I've been using WordPress on a variety of websites for about a year and am worried about switching to another platform.
I have heard very good things about blogengine.net.
Is there a way I can import all my wordpress content into it?

Any kind of help would be greatly appreciated!

# If some one wants to be updated with latest technologies then he must be pay a visit this website and be up to date daily. 2019/05/01 20:18 If some one wants to be updated with latest techno

If some one wants to be updated with latest technologies then he must be pay a visit this
website and be up to date daily.

# Hello, i think that i saw you visited my website so i came to “return the favor”.I'm trying to find things to enhance my site!I suppose its ok to use a few of your ideas!! 2019/05/03 10:12 Hello, i think that i saw you visited my website s

Hello, i think that i saw you visited my website so i came to “return the favor”.I'm trying to find
things to enhance my site!I suppose its ok to use a
few of your ideas!!

# I was suggested this web site by my cousin. I'm not sure whether this post is written by him as nobody else know such detailed about my difficulty. You are amazing! Thanks! natalielise plenty of fish 2019/07/26 20:04 I was suggested this web site by my cousin. I'm no

I was suggested this web site by my cousin.
I'm not sure whether this post is written by him as nobody
else know such detailed about my difficulty.
You are amazing! Thanks! natalielise plenty of fish

# I was suggested this web site by my cousin. I'm not sure whether this post is written by him as nobody else know such detailed about my difficulty. You are amazing! Thanks! natalielise plenty of fish 2019/07/26 20:05 I was suggested this web site by my cousin. I'm no

I was suggested this web site by my cousin.
I'm not sure whether this post is written by him as nobody
else know such detailed about my difficulty.
You are amazing! Thanks! natalielise plenty of fish

# I was suggested this web site by my cousin. I'm not sure whether this post is written by him as nobody else know such detailed about my difficulty. You are amazing! Thanks! natalielise plenty of fish 2019/07/26 20:06 I was suggested this web site by my cousin. I'm no

I was suggested this web site by my cousin.
I'm not sure whether this post is written by him as nobody
else know such detailed about my difficulty.
You are amazing! Thanks! natalielise plenty of fish

# I was suggested this web site by my cousin. I'm not sure whether this post is written by him as nobody else know such detailed about my difficulty. You are amazing! Thanks! natalielise plenty of fish 2019/07/26 20:07 I was suggested this web site by my cousin. I'm no

I was suggested this web site by my cousin.
I'm not sure whether this post is written by him as nobody
else know such detailed about my difficulty.
You are amazing! Thanks! natalielise plenty of fish

# My partner and I stumbled over here by a different website and thought I might as well check things out. I like what I see so now i'm following you. Look forward to finding out about your web page again. 2019/08/01 0:41 My partner and I stumbled over here by a different

My partner and I stumbled over here by a different website
and thought I might as well check things out.
I like what I see so now i'm following you. Look forward to finding
out about your web page again.

# My partner and I stumbled over here by a different website and thought I might as well check things out. I like what I see so now i'm following you. Look forward to finding out about your web page again. 2019/08/01 0:42 My partner and I stumbled over here by a different

My partner and I stumbled over here by a different website
and thought I might as well check things out.
I like what I see so now i'm following you. Look forward to finding
out about your web page again.

# My partner and I stumbled over here by a different website and thought I might as well check things out. I like what I see so now i'm following you. Look forward to finding out about your web page again. 2019/08/01 0:43 My partner and I stumbled over here by a different

My partner and I stumbled over here by a different website
and thought I might as well check things out.
I like what I see so now i'm following you. Look forward to finding
out about your web page again.

# My partner and I stumbled over here by a different website and thought I might as well check things out. I like what I see so now i'm following you. Look forward to finding out about your web page again. 2019/08/01 0:44 My partner and I stumbled over here by a different

My partner and I stumbled over here by a different website
and thought I might as well check things out.
I like what I see so now i'm following you. Look forward to finding
out about your web page again.

# re: Oracle??Select???????? 2021/08/07 23:43 can hydroxychloroquine get you high

is chloroquine an antibiotic https://chloroquineorigin.com/# hidroxicloroquina 400mg

# creative college essays h30kgw 2022/09/03 15:28 Charlosmox


Nicely put. Kudos. https://definitionessays.com/ post graduate thesis

# which is the best essay writing service d603az 2022/09/08 17:15 Charlosmox


Regards! A good amount of data!
https://definitionessays.com/ successful college essay

# thesis statement for cause and effect essay f26gwg 2023/02/09 21:09 Albertosed

You reported it terrifically.

https://service-essay.com/ service to others essay

# what are the best paper writing services k19quh 2023/03/01 2:50 StevenGrelo

You mentioned it wonderfully.
pay for paper writing https://service-essay.com/ buying papers online college

# thesis satement y80ptd 2023/03/03 1:52 Josephbried


Thanks! Excellent stuff!
thesis statement about online learning https://writingthesistops.com/ qualified thesis

# help me to write an essay n98qsj 2023/03/06 6:42 EugeneSib


Seriously a good deal of great data!
college personal statement essay https://essaywritingservicebbc.com writing a theme essay https://essaywritinghelperonline.com

# essay service cheap k90slj 2023/03/06 18:21 Gregorysaipt

You actually revealed that perfectly!
how to write a conclusion in an essay https://bestonlinepaperwritingservices.com buy thesis https://helptowriteanessay.com

# easy essay writing b26qec 2023/03/06 21:51 EugeneSib


Nicely put. Appreciate it.
buy admission essay https://writingthesistops.com creative college essay prompts https://bestpaperwritingservice.com

# business letter writing services i284xt 2023/03/07 12:40 EugeneSib


Many thanks! Excellent information!
best essay cheap https://researchproposalforphd.com write my paragraph for me https://essaywriting4you.com

# buy phd thesis a39rox 2023/03/08 4:55 EugeneSib

You actually expressed it effectively.
order custom essays online https://buycheapessaysonline.com college essay harvard https://writinganessaycollegeservice.com

# buy custom essay papers j534co 2023/03/08 20:31 EugeneSib

You mentioned this superbly!
persuasive essay writing https://bestonlinepaperwritingservices.com college essay writers block https://homeworkcourseworkhelps.com

# essay help service v91aic 2023/03/09 12:36 EugeneSib


Cheers, A lot of knowledge.
essays writing help https://researchproposalforphd.com thesis for master degree https://dissertationwritingtops.com

# writing dissertations c49qec 2023/03/10 3:14 EugeneSib


Info effectively regarded..
professional article writing services https://custompaperwritersservices.com how to write an abstract for a dissertation https://custompaperwritingservices.com

# college application essay editing i40bmo 2023/03/10 10:28 Gregorysaipt


Thanks! A good amount of write ups!
methodology dissertation https://bestpaperwritingservice.com help write essay for me https://hireawriterforanessay.com

# write my essay for me no plagiarism e222jy 2023/03/11 8:35 EugeneSib

You explained that really well.
essay writing services for cheap https://writeadissertation.com writing personal essay https://essayservicehelp.com

# easy college essay prompts e64tfp 2023/03/12 5:51 Gregorysaipt


Really tons of good tips.
write a essay about yourself https://englishessayhelp.com how to write an analysis essay https://domyhomeworkformecheap.com

# how to write a play in an essay i75evc 2023/03/12 14:09 EugeneSib


Great content. Thanks!
best cv writing service london https://helpwritingdissertation.com writing an essay introduction https://buycheapessaysonline.com

# writing experience essay p85kwd 2023/03/13 3:37 Gregorysaipt


Cheers. Useful information!
essay writing prompts https://helpmedomyxyzhomework.com how to write essay for scholarship https://hireawriterforanessay.com

# write and essay q30bmb 2023/03/14 1:27 Gregorysaipt


Amazing loads of useful knowledge!
personal statement college essay https://essaywritingserviceahrefs.com help writing essays for college https://bestpaperwritingservice.com

# professional custom writing services p89njc 2023/04/01 8:05 EugeneSib


Wow lots of great facts!
essay writers net https://hireawriterforanessay.com how to find college essay prompts https://quality-essays.com

# The plugins developed for WordPress 2023/05/09 23:16 Justas

The plugins developed for WordPress serve to enhance the features and functions of a WordPress website, allowing you to build your awesome and functional site https://t.me/wpigaming/648 Customise WordPress with powerful, professional and intuitive fields.

# First of all I would like to say great blog! I had a quick question that I'd like to ask if you do not mind. I was interested to know how you center yourself and clear your thoughts prior to writing. I've had a difficult time clearing my mind in getting 2024/04/02 18:53 First of all I would like to say great blog! I ha

First of all I would like to say great blog!
I had a quick question that I'd like to ask if you do not
mind. I was interested to know how you center
yourself and clear your thoughts prior to writing. I've had a difficult time clearing my
mind in getting my ideas out there. I truly do enjoy writing but it just
seems like the first 10 to 15 minutes are wasted simply just trying to figure out how to begin. Any suggestions or
tips? Many thanks!

# Howdy! This blog post couldn't be written much better! Going through this article reminds me of my previous roommate! He continually kept talking about this. I most certainly will send this post to him. Fairly certain he's going to have a very good rea 2024/04/04 7:48 Howdy! This blog post couldn't be written much bet

Howdy! This blog post couldn't be written much better!
Going through this article reminds me of my previous roommate!
He continually kept talking about this. I most certainly will send this post to him.
Fairly certain he's going to have a very good read. Many thanks for sharing!

# Hi there mates, how is all, and what you wish for to say about this article, in my view its genuinely remarkable in favor of me. 2024/04/10 23:11 Hi there mates, how is all, and what you wish for

Hi there mates, how is all, and what you wish for to say about this article, in my view its genuinely remarkable in favor of me.

# Excellent post. I'm dealing with many of these issues as well.. 2024/05/03 5:09 Excellent post. I'm dealing with many of these iss

Excellent post. I'm dealing with many of these issues as well..

タイトル
名前
Url
コメント