14827 items (1495 unread) in 26 feeds
Database
(1495 unread)
(10 unread)
作者:Fenng 发布在 dbanotes.net. 
在修改后的 《闲谈 Web 图片服务器》 一文中也提及了"IE 浏览器的连接数问题",这也是个有趣的话题。值得补充记录一下。

这个数据来自 Roundup on Parallel Connections ,这是一篇好贴,里面的每个线索几乎都值得一读(Opera 9 的连接数我做了修改)。以前经常看到某些优化 IE 或者优化 Firefox 的插件或工具,其工作原理也不过是针对这些相关的网络参数合理组合罢了。 好多朋友说 Opera 快,其实可能就是压缩和连接数两个做的更适合现在的网络吧。我不太相信内置解析器什么的真能比其它浏览器有什么质的领先。
其中 Firefox 3 的连接数目前还处于不确定中。对于网站维护人员,这是个非常值得重视的信息,我们总说蝴蝶效应,这恐怕就是最直接的例子了。一旦 IE 8 确定了新的默认连接数,并且短期内大量用户下载,有些网站如果不做调整的话,很可能会被击垮。
--EOF--
相关文章|Related Articles
评论数量(6)|Add Comments
本文网址:[www.dbanotes.net]
最近作者还说了什么? Follow Twitter / Fenng
DBA notes 理念: 用最简约的技术取得最大的收益!
This time, the question is not because it was poorly phrased. It is because it is regarding an area I want to bring to the attention of a larger audience.
The question went like this:
<quote>
Suppose, I have a table having country currency combinations with a primary currency. The below is a sample data.
Country Currency Primary_Currency
US USD Y
US USN N
US USS N
And, I have a before update trigger on the above table for each row
(using autonomous transaction to avoid mutating error) to check whether
the country has any primary currency. I am giving the below update.
</quote>
Ok, serious red flags here - They have a business rule apparently that AT MOST one currency can be "primary" for a given country - that is - COUNTRY must be UNIQUE when PRIMARY_CURRENCY='Y' (what I call selective uniqueness). Now, I might suggest we are missing an entity in this model - that is, the primary currency 'flag' should not be there, but rather there should be two entities - primary_currency, and other_currencies - perhaps. Then, the problem is simple - COUNTRY would be the primary key of the primary_currency table - and COUNTRY,CURRENCY would be the primary key of the other - an in fact, if the rule was "A country may have at most one primary currency and must have at least one primary currency" - then enforcing that more complex one would be trivial - just add a foreign key from other_currencies to primary_currency - and you are done. Could not be easier.
But - back to the red flags:
So, we have these HUGE red flags - all of which get proven out in the next bit - everything I guessed:
Are shown true:
Update Country_Currency_Ref
set is_primary_currency = 'Y'
where (country_code = 'US' and currency_code = 'USN');
And the trigger is working fine and giving the correct message that it cannot be updated as there
is already one primary currency against that country Now I update the data as below
(No primary currency)
Country Currency Primary_Currency
US USD N
US USN N
US USS N
and try to update the data with the below condition
Update Country_Currency_Ref
set is_primary_currency = 'Y'
where (country_code = 'US' and currency_code <> 'USD');
In this case, the trigger is failing and updating other two records. Why is this behaviour?
And how can we over come the same?
Sorry, the trigger is not failing, the trigger is just doing precisely what it was coded to do. The problem is the person coding the trigger doesn't understand transactions and concurrency controls and how the database works. By using the autonomous transaction to query the table - it is as if they started a brand new session to query that table. Of course that brand new session cannot see any changes made by not yet committed! Including the changes the trigger is trying to validate. This is PRECISELY why we have a mutating table constraint - your row level trigger is being fired as the rows are modified - if you were able to query the table in the trigger without the autonomous transaction - you would see the table half updated (and then what, what a MESS that would be). So, since Oracle is evil and prevents you from doing something bad here - you use an autonomous transaction - you get a consistent view of the table to be sure, but you cannot see the data you are trying to validate!!! That makes validation pretty hard.
Even if you did the "common mutating table constraint workaround" - by deferring your reads until the AFTER (not for each row) trigger, you cannot do this check in a trigger without LOCKING THE TABLE. You would have to serialize access in order to prevent two concurrent sessions from each creating a primary currency record at the same time.
I would prefer a two table solution here:
ops$tkyte%ORA11GR1> create table primary_currency
2 ( country varchar2(2) primary key,
3 currency varchar2(3)
4 )
5 organization index
6 /
Table created.
ops$tkyte%ORA11GR1> create table other_currencies
2 ( country varchar2(2),
3 currency varchar2(3),
4 constraint other_currencies_pk
5 primary key(country,currency),
6 constraint must_have_at_least_one_primary
7 foreign key(country)
8 references primary_currency(country)
9 )
10 organization index
11 /
Table created.
That solves the problem quite elegantly - and even enforces the complex "must have a primary currency" constraint if you implement the foreign key. However, if they were to keep this single table, then I would say:
drop your trigger.
and promise to never use autonomous transactions to avoid mutating table constraints (I said "mutating table CONSTRAINTS", not error - the error is you using an autonomous transaction to destroy your data integrity) ever again.
add:
create unique index only_one_can_be_primary on country_currency_ref
( case when is_primary_currency = 'Y' then country_code end );
I hate triggers
I hate autonomous transactions
I hate when others
If we removed those three things from PLSQL - we would solve 90% of all application bugs I think... No kidding. I know, in the right hands, they are powerful tools. However, they fall into the wrong hands far too often.