Wednesday, November 24, 2010

sql "IN" clause gotcha

Though standard sql puts no limit on the number of entries you can put inside an IN clause, but various vendors typically put a limit. Oracle puts a limit of 1000 to it. This caused a bug in our app as we dynamically generate a sql query where number of entries went beyond 1000 today.

You can put any one of the resolution stated below(in decreasing order of preference)

1. Change your logic so that number of entries never go beyond 1000(it may be a good practice in general to follow).
2. See if you can use "BETWEEN" clause for your particular case.

Instead of using "Select blah from tablexyz WHERE col IN (c1,c2,....c50000)"
3. Use "Select blah from tablexyz WHERE col IN (select id from ctable)" and the subquery "select id from ctable" returns resultset containing c1,c2,...c50000.
4. Use "Select blah from tablexyz WHERE col IN (c1,c2,...c1000) OR col IN (c1001,c1002,...,c2000) OR ... OR col IN (c49001,c49002,...,c50000)".
5. Use multiple sql queries each with one IN clause containing 1000 entries.

Much of above came from this thread.

Tuesday, November 23, 2010

Wrapup - Introduction to probability

On Sep 05' 10 I wrote a plan to work through Introduction to Probability and to finish all the assignments given in probability course in MIT.

Today I'm glad to announce that it is finally finished and all the notes and solutions can be found in these posts.

The reason I studied it is that probability comes up as a basic requirement when you follow any math oriented text on things like Randomized Algorithms, AI, NLP, Machine Learning etc. So, I wanted to get enough grounding in probability basics and this book, as the title suggests, does exactly that. Another plus point is that, its used in the above mentioned MIT course so you have well defined assignments for practice and book also has a lot of exercises with solutions.

And, Thanks(again!) to Ravi for lending the book.

Note: If you need solutions to assignments, they are also available on MIT site. I did them mostly to force myself into doing those problems to make sure I'm not doing the passive reading of the book and it helps you think what you read and in really "getting it". Many times, I could not come up with the solution and I did peek in official solutions :).

probability: problem-set#12

My solutions for problem-set#12 from the MIT introductory probability course.

probability: problem-set#11

My solutions for problem-set#11 from the MIT introductory probability course

probability: problem-set#10

My solutions for problem-set#10 from the MIT introductory probability course.

Tuesday, November 2, 2010

bypassing group policy on windows

Group Policy is a feature of windows operating systems to give centralized control of all the computers on a domain to the system administrators. They can do various things like disabling various actions(such as blocking access to Task Manager, disabling access to IE advanced settings etc).

This post describes, how to bypass the group policy.

This is a two step process.

1. All the settings are stored in the registry, so first step is to find the location of the registry that controls the action you're looking for. A little googling can help you find that or use

2. Start -> Run -> regedit, and set the registry value to whatever you want.

And you are done. But, remember it may go away after some time or when you restart the computer as group policy will update/reset itself periodically and on restarts. Until that time you are all set.

For example, let say access to "Empty temporary internet files folder when browser is closed" option in advanced settings of internet explorer options is disabled and you want to change its value.

1. Find the location of registry. Searching for "empty temporary internet files" in reveals following registry values associated with it.
HKCU\Software\Policies\Microsoft\Windows\CurrentVersion\internet Settings\Cache
HKLM\Software\Policies\Microsoft\Windows\CurrentVersion\internet Settings\Cache

2. Open regedit and set the value to above registries to 1(if you wanted to uncheck the option) or whatever you need.

Restart IE and you'll see the change.

Caution: Doing this might be a cause of concern to your sys admins or against your corporate policies, so do this only if you absolutely have to. And, corruption in windows registry might make your system unusable.

Disclaimer: I'm no windows administration expert, so some of above information may be partially incorrect or there might be better ways to handle it.

probability: problem-set#9

My solutions for problem-set#9 from the MIT introductory probability course.

probability: problem-set#8

My solutions for problem-set#8 from the MIT introductory probability course.

probability: problem-set#7

My solutions for problem-set#7 from the MIT introductory probability course.