Speed up vista

some nice article for your vista

Performance is probably the most coveted intangible when it comes to PCs, and tweaking, to the performance hungry, is considered more of a necessity than an option. Gearheads go to great lengths to get quicker system response times, faster-running games, and shorter PC bootup and shutdown times.

One way is to overclock the heck out of the poor components (and then, for bragging rights, to log on to a message board and claim a stable CPU frequency of about 300MHz faster than what's actually possible). Another way is to tweak out the operating system itself.



Unlike previous Microsoft operating systems, Windows Vista is pretty streamlined right out of the box. It makes terrific use of a system's resources, but it's built as much for pretty looks and increased stability and security as it is for horsepower. It's time now for a course of action that will take the ball and chain off this baby and let it fly.

The ink on Windows Vista's EULA is barely dry, so it's very likely that more speed tips, registry hacks, and deep settings will be revealed in the weeks, months, and years to come. For now, here's our set of tweaks that can help you turn up the throttle on your new operating system. Continued... ExtremeTech and lots of other Web sites have published quite a few bytes of copy about how drivers for Vista are premature at best. Graphics drivers, especially, are hurting in terms of efficiency and stability. It's likely that the biggest boost you're likely to see will come in gradual increments as AMD, Nvidia, and other companies work out the wrinkles that prevent their hardware from performing at peak under the new OS.

The first step in optimizing Vista, then, is to keep your drivers up to date. Check for new drivers for all of your hardware often—daily, even. Not only can new drivers enhance performance, they should also gradually enable more features. We're still waiting for better video quality from AMD's ATI cards, for instance, and for a full feature set for Creative Labs' SoundBlaster X-Fi cards.

Lose What You Don't Need
If you installed Vista yourself and have experience installing previous Windows OSes, you surely noticed that Vista hardly asks any questions about your computer—and what you plan to do with it—than did prior OSes. Windows Vista makes all kinds of assumptions about your computing habits and the features you may or may not need, and it inevitably installs some overhead that you simply don't need. You can get rid of it. Windows XP had the Add/Remove Windows Features button in the Control Panel Add/Remove Programs applet, and Vista has something like it.
Open Control Panel and click Uninstall a Program to launch Vista's Uninstall or Change a Program Window. In the Tasks pane on the left, click Turn Windows Features On or Off.
Check the list of features. Each feature is preceded by a checkbox which, if filled, indicates the feature is installed. If you hover the mouse over a feature, a help tooltip appears to tell you what it is.
Uncheck any feature you don't need. Some of the features are headings with a sub-list below them; just click the little + sign to expand.

For my gaming system, I've purged everything except:
Some of the games
XPS Viewer (under .NET Framework 3.0)
Remote Differential Compression (a network optimizer)
Windows Ultimate Extras

Note that when you uncheck features, you're not removing these features from your system; you're simply turning them off so they don't sit in the background eating up resources. You can turn any of them back on by invoking this window and filling the checkboxes. Continued...

Next, it's time to flush any services that you don't want or need.

Click the Start button and type in services.msc and hit Enter. (The cursor jumps to the Search bar in the Start Menu when you click the Start button; you can usually just punch in whatever program or module you want to run right there).

The Services applet appears. Each service is basically a little nest of software support code for something the computer can monitor or do.

Well-written services include a description of what they do (note that lots of third-party services don't include a description, to which we say: shame). The Status column in the Services window shows whether or not the service has been started. Startup Type means how the service starts:
Automatic means the service starts when Windows starts.
Manual means the service starts when Windows detects that something needs it.
Disabled means the service doesn't start at all.

Most services are either set to Automatic or Manual. There's no need to change any manual services; they only start when it's necessary for them to do something. There are probably some automatic services you really don't need, though. You can find a full list of services at TweakHound, an excellent source of all kinds of tweaks.

To change how a service starts, right-click it and click Properties. If you don't want a service to load, first stop the service by clicking Stop. Then, pull down the Startup Type list and set the service to Manual or Disabled.

If you're not sure about a service, it's safer to set it to Manual; that way, if something calls it, it should start up. If you know you don't need a service, set it to Disabled.

The services you need depend on what you do with your PC. For instance, if you're not using ReadyBoost, you can disable that service; you can disable Windows Error Reporting if you don't want to report errors; you can disable Tablet PC Input Service if you don't want to use Tablet PC features; and so on.

You can almost certainly disable some services that start automatically by default:
Computer Browser
Distributed Link Tracking Client
IKE and AuthIP IP Keying Modules
Offline Files
Remote Registry
Tablet PC Input Service (unless you're using a tablet PC)
Windows Error Reporting

Some services that you absolutely should not disable include:
Multimedia Class Scheduler
Plug and Play
Superfetch
Task Scheduler
Windows Audio
Windows Driver Foundation

Feel free to experiment with services; just keep track of which services you tweak and, if something doesn't work, re-enable the last service you turned off. Streamline the system by shutting down as many services as you can, based on your own unique needs.

As an example, here are the services I've disabled on my networked gaming machine:
DFS Replication
Computer Browser
Distributed Link Tracking Client
IKE and AuthIP IPsec Keying Modules
IP Helper
IPsec Policy Agent
KtmRm for Distributed Transaction Coordinator
Offline Files
Remote Registry
Secondary Logon
Security Center (Use caution if you disable security services!)
SSDP Discovery
Tablet PC Input Service
Terminal Services
Windows Defender (Ditto the above warning!)
Windows Error Reporting Service Continued...
For the most streamlined operation, it's essential that your computer has as few programs running in the background as possible. You can tell a bit about how much junk is running behind the scenes by looking at the system tray (the area next to the clock on the taskbar). The more icons you see there, the more stuff is running that you may not actually need.

I recommend a two-step process for getting rid of any background applets that you don't need. Check out the tray icons and use the interfaces from those programs to disable them natively. Then, run good old MSCONFIG to clean out anything else.

First, look at the tray. Some of the stuff there belongs there; you might see a little speaker icon, a battery power icon, an icon for the Sidebar, network status icons, and a few other odds and ends that Windows puts in the tray. Look for third-party icons; in the picture shown here, QuickTime and Steam occupy parts of the tray.

Right-click on any icons you find that aren't simple Windows status icons. Look for a settings, properties, or a similar option. Then, in the resulting window, look for a way to prevent the program from loading when Windows starts. For example, to prevent Steam from automatically loading, you would:
Right-click the Steam tray icon.
Click Settings.
Click Interface (see the screenshot below).
Uncheck Run Steam When Windows Starts.
Click OK.

Quicktime, however, presents a challenge. You can tell it not to display the tray icon, but it will still run in the background. For that, and other programs that don't always display tray icons, use the second method. Continued... Click the Start button, type msconfig, and hit Enter.

You'll see the System Configuration window, which operates essentially the same as it does in Windows XP. Click the Startup tab.

Look at the list of startup items. Each is preceded by a checkbox. You can prevent any of these programs from starting simply by unchecking it.

You'll note that QuickTime, which wouldn't let me disable it through its interface, is there. Simply uncheck it to prevent it from running in the background—and sucking up resources.

Steam, QuickTime, and many other such programs will start automatically when they're needed. For example, if you launch an MOV file, QuickTime will start whether or not its little applet is running in the background. Steam will launch if you start a Steam game, even if it's not running behind the scenes.

Now, some items are necessary. You might see things like a mouse or gamepad applet that's the hardware needs to offer its programmability. You might see Windows Defender, which, if your computer has constant Internet access and lacks another anti-spyware program, could help protect it.

Here's a good rule of thumb: If an application in MSCONFIG references hardware, you should keep it. If it references software, get rid of it (unless it's a vital security program). Hardware applets often supply needed front ends; software applets usually help a software program open faster. Software opens just fine without helper applets, so there's no need for them to suck up processor cycles all the time.

When you've cleaned out the list, unchecking anything you don't need, restart the computer. Continued... ReadyBoost is a Vista feature that uses a compatible USB flash device to enhance performance. Note that the oft-misunderstood feature isn't a replacement for a memory upgrade, and it doesn't affect game performance—you won't see higher frame rates by adding a keychain drive to your system.

ReadyBoost caches disk reads on the fly and can often speed up data access. Reads from a USB key or other ReadyBoost device are much faster than random reads from a platter on the hard drive. ReadyBoost data is encrypted, so if someone swipes the flash device he or she can't tell what you've been up to. It's secure, and it really does speed up access in certain instances.

To enable ReadyBoost, just plug in a flash device (Microsoft recommends one about the same size as your system's main memory. For instance, if you have 1GB of RAM, grab a 1GB ReadyBoost device). The system will automatically detect the drive and offer to use it either as an external drive or as a ReadyBoost drive. Simply choose the latter, and a window like the one in this screenshot will appear.

You can change the amount of memory on the device is used for speed. Windows will recommend the amount it can use with the most efficiency. Click OK and you're done.

Adding a ReadyBoost drive isn't like doubling your system's memory, but the performance benefits are well worth the price of a USB flash device. Continued... Windows Vista features what some of us think is the prettiest GUI in the OS industry. Its stylish transparencies and nifty animations—driven by Direct3D and your graphics card—give it a polished look that's a pleasure to use.

Unfortunately, that shiny, new interface, called Aero, is also a resource hog. If you're running Vista on a PC that's near or just above the system requirements, you might want to shut off some or all of those features.

Here are some actions you might want to take to tweak interface niceties:
Lose the transparency. Right-click the desktop, click Personalize, and click Windows Color and Appearance. Uncheck Enable Transparency. Click OK.
Get rid of the Sidebar. It's cool, but some of those gadgets chow down on memory. Right-click the Sidebar, click Properties, and uncheck Start Sidebar When Windows Starts. Click OK. Then, right-click the Sidebar and click Close Sidebar. If you ever want it back, you can simply click the Start button and key in "sidebar" and hit Enter.
Get rid of some of the visual effects. Open Control Panel, click Performance and System Tools, and click Adjust Visual Effects. In the resulting window, you can uncheck line items for animations, fades, and other effects; or simply click Adjust For Best Performance.
Go with a non-Aero theme. To get rid of Aero entirely, use the Windows Classic, Windows Vista Basic, or Windows Standard theme. Right-click the desktop, click Personalize, and click Windows Color and Appearance. Click Open Classic Appearance Properties... and choose a theme in the Color Scheme list box. Click OK.

When you perform such tweaks, Windows Vista won't look as pretty. It will, however, respond much faster. A high-end system might not benefit a whole lot from these adjustments, but they'll improve low-end computers in spades. Continued... Next up are a few hacks I've come across in my travels. The first is for systems that have an uninterruptible power supply (UPS) with a reliable battery attached.

If your system is equipped with a serial-ATA (SATA) hard drive, go to Device Manager (the quickest way to do that is to click Start and punch in "Device Manager" and hit Enter). Expand the Disk Drives entry. Right-click on your SATA hard drive and click Properties. Click the Policies tab, and click Enable Advanced Performance. This option enables extremely aggressive write caching, which can speed up drive access but also cause you to lose data if the power goes out suddenly.

A couple of tweaks require you to hack the registry. To do this, click the Start button, type regedit and hit Enter.

Note: You should make a backup of the registry before you alter it. Click File, click Export, and in the resulting window, make sure All is selected at the bottom. Give the file a name and click Save. This will create a full backup of your Windows registry; if you accidentally hose something, you can go into Windows Safe Mode and restore it. Alternately, you can create a Restore Point before you alter the registry; go to Control Panel, then System and Maintenance, and then System. Click System Protection in the Tasks list. Click the Create... button, and follow the prompts.

I recommend two registry hacks for minor performance gains. First, turn off the low disk space checks:
Using the left side of the Registry Editor, navigate to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies
Right-click in the right pane and select New Key.
Name the new key Explorer.
In the Explorer key, right-click in the right pane and click New DWORD (32-bit) Vaue.
Name the DWORD NoLowDiskSpaceChecks.
Right-click the new DWORD and click Modify.
Set the Value Data to 1.
Click OK.

This will prevent Windows Vista from checking the space on your hard drive and popping up the notorious "Hey, you're running out of space!" warning balloon.

Next, you can probably safely disable the NTFS habit of creating 8.3 versions of filenames for backward compatibility. DOS is dead, right?

Open the Registry Editor and:
Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
Find the DWORD called NtfsDisable8dot3NameCreation.
Right-click it and click Modify.
Change the value to 1.
Click OK.

You should reboot after you alter the registry. These tweaks mildly speed up hard drive access by removing needless overhead. Continued... If you've somehow gotten the impression that Windows Vista doesn't need to be defragged, think again. Vista comes with a defrag program (Microsoft's worst yet, in terms of usability) and it even comes preconfigured to defrag the hard drive once each week.

Unless you keep your computer on 24 hours a day, launch Disk Defragmenter (click Start and type in "defrag" and hit Enter) and disable its scheduler. You can do this on your own, with a better defrag application which, unlike Microsoft's, still shows you a map of the drive as it defrags.

Download Disk-Defrag from AusLogics and install it. Then run it. It's speedy and free.

Unless you install and uninstall programs, move and delete data, and otherwise assault the hard drive regularly, you don't need to defrag more than once a month. Pick a night after you're done with your PC, start the Disk-Defrag application, start a defragmentation, and go to bed.

Use It
The last way to speed up Windows Vista that we'll cover is simple.

Use it.

Vista's Superfetch feature, its prefetching powerhouse, is incredibly powerful on its own—don't mess with it.

Read about our Ten Must-Have Gadgets for Windows Vista Sidebar.

Vista monitors your computing habits and caches the stuff you use the most. It also moves things on the hard drive that it thinks you'll want to the fastest area of the platter. It does all kinds of background work to speed up, tune itself up, and make itself as responsive as it can be.

Use Vista regularly and, in about a week, it should be fully optimized based on what you do. Windows XP started the trend with its own self-optimization, but Vista truly gets it right. Vista's own optimization isn't perfect, but the steps in this article will boost it so that it's even more responsive and well-tuned.

J2EE more problem

The vast majority of server-side Java programmers have J2EE on their resumes, they pride themselves for being experts in this particular technology but there’s a problem. Many of these programmers have their minds warped into the J2EE way of thinking:

1. There is nothing beyond the database
2. POJOs focused purely on business logic
3. This is distributed programming
4. Ops is someone elses problem
5. Deploy more or bigger boxes to scale

Most enterprises can comfortably tolerate systems built this way but what if you’re not most enterprises? What if you are an eBay or a MySpace? eBay for example have thrown out almost all of J2EE and built their own libraries to tackle the problems they face around:

1. Monitoring
2. Hot Upgrades
3. Scaling

Basically once you’re beyond a certain level of challenge the J2EE way of thought and patterns of design don’t work. So where does one find Java programmers that can cope with such a challenge? They’re going to need serious knowledge of:

1. Deployment
2. Monitoring
3. Networking
4. FLP
5. SEDA
6. Threads
7. REST

But put that on a job advert and see how many responses you get! J2EE is a raging success to be sure but if you’re a company that can’t use it you’re likely going to be a victim of that success when looking to hire server-side Java programmers.

All of this has me wondering how one should frame job adverts of this nature. Should we even bother asking for Java experience or simply drop the language/platform constraint entirely? What should we be asking for? Multi-user online game programming perhaps? What else?

Java 6 features

This is some java 6 features

Scripting
I was sold into scripting the JVM since back in the day when the only scripting option was Jython and BeanShell. Personally I would have preferred if Groovy was the default scripting language that came with Java SE 6. The good thing is that there are plenty of scripting languages that support the new Scripting Framework.

No More Class.forName for JDBC Driver
Java SE 6 does not require you to load the JDBC driver prior to creating a JDBC connection. This only works if the driver is packaged with a certain descriptor in the jar file. This only saves me one line of code, but I would never for the life of remember the name of driver I wanted. So in reality this saves one line of code and one Google search.

System Tray
The system tray goes a long way in developing Java applications that look and behave more like native applications. The system tray was originally part of the JDesktop Integration Components (JDIC). They system tray allows you to add a menu on the user desktop's user tray.

Java Compiler API
In the past I have had to compile Java source at runtime by invoking the the Main class for the javac command. The Java Compiler API provides a solid solution for compiling Java source files or just in-memory Java code.

XML Binding
I cannot stress how useful and powerful XML binding is. XML binding is object serialization using XML. With JAXB as part of the Java SE 6 you don't have to download additional jars and libraries.

JDBC 4.0 Annotations
Early Java 6 builds introduced a BaseQuery interface. You where able to sub-interface the interface and then define get methods and associated annotation with the appropriate select prepared SQL statement. JDBC annotations are a new way of building Data Access Objects (DAO) which looked appealing. I thought this feature was innovative, yet it didn't make the final cut. I was not able to find word if this will be available as a standalone library.

SE 6 on OS X
Another thing that I am not happy with in regards to Java 6 is that I can only use Java 6 on my Windows machine. There seems to be no word from Apple as to when Java SE 6 will be able for OS X. As OS X languishes with Java SE 6 support, Ubuntu has promised to provide a complete Java development stack with Java SE 6, GlassFish, and NetBeans.

Im going fat

Hueee im 80kg. i dont believe it.
All my friend and my gf always say im fat.

i have to commit that i will 70kg at the end of 2007

Becareful of Maxgain and Ganesha company

Yesterday my gf is called by PT. Maxgain and PT. Ganesha for interview.
I ussualy check company name to google to make sure, and i found bad news in some blog.
i forgot the link, just check in google ryosaeba blog and priyadi blog.

They said both company is weird, offering high salary but they want us to give them some money to invest.

So becareful

apache Tomcat 6 released

Apache has released the new version of Tomcat, 6.0.10.
Tomcat 6 implements servlet 2.5 and jsp 2.1

http://tomcat.apache.org/

Top 10 J2EE performance problems

When i read top 10 j2ee problem in vincent blog http://blog.xebia.com/2007/04/30/ejapp-top-10-countdown-wrap-up/


I think not all that list is true. i disagree point 1 and 4
e.g point number 1, off course this mistake is in design phase not part of J2EE. You shold blame your system analyst or your DBA for this.


point number 4, is adding a library to our application. i think if we put library we dont needed in our apps does not impact the performance, cause library we dont need is idle unless we use it.

Query optimizer

I've found this interesting article for you guys who want optiomize your query.

Enjoy reading.


This tip may sound obvious to most of you, but I have seen professional developers, in two major SQL Server-based applications used worldwide, not follow it. And that is to always include a WHERE clause in your SELECT statement to narrow the number of rows returned. If you don't use a WHERE clause, then SQL Server will perform a table scan of your table and return all of the rows. In some case you may want to return all rows, and not using a WHERE clause is appropriate in this case. But if you don't need all the rows returned, use a WHERE clause to limit the number of rows returned.

By returning data you don't need, you are causing SQL Server to perform I/O it doesn't need to perform, wasting SQL Server resources. In addition, it increases network traffic, which can also lead to reduced performance. And if the table is very large, a table scan will lock the table during the time-consuming scan, preventing other users from accessing it, hurting concurrency.

Another negative aspect of a table scan is that it will tend to flush out data pages from the cache with useless data, which reduces SQL Server's ability to reuse useful data in the cache, which increases disk I/O and hurts performance. [6.5, 7.0, 2000] Updated 1-24-2006

*****

In a WHERE clause, the various operators used directly affect how fast a query is run. This is because some operators lend themselves to speed over other operators. Of course, you may not have any choice of which operator you use in your WHERE clauses, but sometimes you do.

Here are the key operators used in the WHERE clause, ordered by their performance. Those operators at the top will produce results faster than those listed at the bottom.

  • =
  • >, >=, <, <=
  • LIKE
  • <>

This lesson here is to use = as much as possible, and <> as least as possible. [6.5, 7.0, 2000] Updated 1-24-2006

*****

In a WHERE clause, the various operands used directly affect how fast a query is run. This is because some operands lend themselves to speed over other operands. Of course, you may not have any choice of which operand you use in your WHERE clauses, but sometimes you do.

Here are the key operands used in the WHERE clause, ordered by their performance. Those operands at the top will produce results faster than those listed at the bottom.

  • A single literal used by itself on one side of an operator.
  • A single column name used by itself on one side of an operator, a single parameter used by itself on one side of an operator.
  • A multi-operand expression on one side of an operator.
  • A single exact number on one side of an operator.
  • Other numeric number (other than exact), date, and time.
  • Character data, NULLs.

The simpler the operand, and using exact numbers, provides the best overall performance. [6.5, 7.0, 2000] Updated 1-24-2006

*****

If a WHERE clause includes multiple expressions, there is generally no performance benefit gained by ordering the various expressions in any particular order. This is because the SQL Server Query Optimizer does this for you, saving you the effort. There are a few exceptions to this, which are discussed on this web site. [7.0, 2000] Added 1-24-2006

*****

By default, some developers, especially those who have not worked with SQL Server before, routinely include code similar to this in their WHERE clauses when they make string comparisons:

SELECT column_name FROM table_name
WHERE LOWER(column_name) = 'name'

In other words, these developers are making the assuming that the data in SQL Server is case-sensitive, which it generally is not. If your SQL Server database is not configured to be case sensitive, you don't need to use LOWER or UPPER to force the case of text to be equal for a comparison to be performed. Just leave these functions out of your code. This will speed up the performance of your query, as any use of text functions in a WHERE clause hurts performance.

But what if your database has been configured to be case-sensitive? Should you then use the LOWER and UPPER functions to ensure that comparisons are properly compared? No. The above example is still poor coding. If you have to deal with ensuring case is consistent for proper comparisons, use the technique described below, along with appropriate indexes on the column in question:

SELECT column_name FROM table_name
WHERE column_name = 'NAME' or column_name = 'name'

This code will run much faster than the first example. [6.5, 7.0, 2000] Updated 1-24-2006

*****

Try to avoid WHERE clauses that are non-sargable. The term "sargable" (which is in effect a made-up word) comes from the pseudo-acronym "SARG", which stands for "Search ARGument," which refers to a WHERE clause that compares a column to a constant value. If a WHERE clause is sargable, this means that it can take advantage of an index (assuming one is available) to speed completion of the query. If a WHERE clause is non-sargable, this means that the WHERE clause (or at least part of it) cannot take advantage of an index, instead performing a table/index scan, which may cause the query's performance to suffer.

Non-sargable search arguments in the WHERE clause, such as "IS NULL", "<>", "!=", "!>", "!<", "NOT", "NOT EXISTS", "NOT IN", "NOT LIKE", and "LIKE '%500'" generally prevents (but not always) the query optimizer from using an index to perform a search. In addition, expressions that include a function on a column, expressions that have the same column on both sides of the operator, or comparisons against a column (not a constant), are not sargable.

But not every WHERE clause that has a non-sargable expression in it is doomed to a table/index scan. If the WHERE clause includes both sargable and non-sargable clauses, then at least the sargable clauses can use an index (if one exists) to help access the data quickly.

In many cases, if there is a covering index on the table, which includes all of the columns in the SELECT, JOIN, and WHERE clauses in a query, then the covering index can be used instead of a table/index scan to return a query's data, even if it has a non-sargable WHERE clause. But keep in mind that covering indexes have their own drawbacks, such as producing very wide indexes that increase disk I/O when they are read.

In some cases, it may be possible to rewrite a non-sargable WHERE clause into one that is sargable. For example, the clause:

WHERE SUBSTRING(firstname,1,1) = 'm'

Can be rewritten like this:

WHERE firstname like 'm%'

Both of these WHERE clauses produce the same result, but the first one is non-sargable (it uses a function) and will run slow, while the second one is sargable, and will run much faster.

WHERE clauses that perform some function on a column are non-sargable. On the other hand, if you can rewrite the WHERE clause so that the column and function are separate, then the query can use an available index, greatly boosting performance. For example:

Function Acts Directly on Column, and Index Cannot Be Used:

SELECT member_number, first_name, last_name
FROM members
WHERE DATEDIFF(yy,datofbirth,GETDATE()) > 21

Function Has Been Separated From Column, and an Index Can Be Used:

SELECT member_number, first_name, last_name
FROM members
WHERE dateofbirth <>

Each of the above queries produces the same results, but the second query will use an index because the function is not performed directly on the column, as it is in the first example. The moral of this story is to try to rewrite WHERE clauses that have functions so that the function does not act directly on the column.

WHERE clauses that use NOT are not sargable, but can often be rewritten to remove the NOT from the WHERE clause, for example:

WHERE NOT column_name > 5

To:

WERE column_name <= 5

Each of the above clauses produces the same results, but the second one is sargable.

If you don't know if a particular WHERE clause is sargable or non-sargable, check out the query's execution plan in Query Analyzer. Doing this, you can very quickly see if the query will be using index lookups or table/index scans to return your results.

With some careful analysis, and some clever thought, many non-sargable queries can be written so that they are sargable. Your goal for best performance (assuming it is possible) is to get the left side of a search condition to be a single column name, and the right side an easy to look up value. [6.5, 7.0, 2000] Updated 1-24-2006

*****

If you currently have a query that uses NOT IN, which offers poor performance because the SQL Server optimizer has to use a nested table scan to perform this activity, instead try to use one of the following options instead, all of which offer better performance:

  • Use EXISTS or NOT EXISTS.
  • Use IN.
  • Perform a LEFT OUTER JOIN and check for a NULL condition.

[6.5, 7.0, 2000] Updated 1-24-2006

*****

When you have a choice of using the IN or the EXISTS clause in your Transact-SQL, you will generally want to use the EXISTS clause, as it is usually more efficient and performs faster. [6.5, 7.0, 2000] Updated 1-24-2006

*****

If you run into a situation where a WHERE clause is not SARGable because of the use of a function on the right side of an equality sign (and there is no other way to rewrite the WHERE clause), consider creating an index on a computed column instead. This way, you avoid the non-SARGable WHERE clause altogether, using the results of the function in your WHERE clause instead.

Because of the additional overhead required for indexes on computed columns, you will only want to do this if you need to run this same query over and over in your application, thereby justifying the overhead of the indexed computed column. [2000] Updated 2-5-2007

*****

If you find that SQL Server uses a TABLE SCAN instead of an INDEX SEEK when you use an IN or OR clause as part of your WHERE clause, even when those columns are covered by an index, consider using an index hint to force the Query Optimizer to use the index.

For example:

SELECT * FROM tblTaskProcesses WHERE nextprocess = 1 AND processid IN (8,32,45)

takes about 3 seconds, while:

SELECT * FROM tblTaskProcesses (INDEX = IX_ProcessID) WHERE nextprocess = 1 AND processid IN (8,32,45)

returns in under a second. [7.0, 2000] Updated 6-21-2004 Contributed by David Ames

*****

If you use LIKE in your WHERE clause, try to use one or more leading characters in the clause, if possible. For example, use:

LIKE 'm%'

Not:

LIKE '%m'

If you use a leading character in your LIKE clause, then the Query Optimizer has the ability to potentially use an index to perform the query, speeding performance and reducing the load on SQL Server.

But if the leading character in a LIKE clause is a wildcard, the Query Optimizer will not be able to use an index, and a table scan must be run, reducing performance and taking more time.

The more leading characters you can use in the LIKE clause, the more likely the Query Optimizer will find and use a suitable index. [6.5, 7.0, 2000] Updated 3-20-2006

*****

If your application needs to retrieve summary data often, but you don't want to have the overhead of calculating it on the fly every time it is needed, consider using a trigger that updates summary values after each transaction into a summary table.

While the trigger has some overhead, overall, it may be less that having to calculate the data every time the summary data is needed. You may have to experiment to see which method is fastest for your environment. [6.5, 7.0, 2000] Updated 3-20-2006

*****

When you have a choice of using the IN or the BETWEEN clauses in your Transact-SQL, you will generally want to use the BETWEEN clause, as it is much more efficient. For example:

SELECT customer_number, customer_name
FROM customer
WHERE customer_number in (1000, 1001, 1002, 1003, 1004)

Is much less efficient than this:

SELECT customer_number, customer_name
FROM customer
WHERE customer_number BETWEEN 1000 and 1004

Assuming there is a useful index on customer_number, the Query Optimizer can locate a range of numbers much faster (using BETWEEN) than it can find a series of numbers using the IN clause (which is really just another form of the OR clause). [6.5, 7.0, 2000] Updated 3-20-2006

*****

If possible, try to avoid using the SUBSTRING function in your WHERE clauses. Depending on how it is constructed, using the SUBSTRING function can force a table scan instead of allowing the optimizer to use an index (assuming there is one). If the substring you are searching for does not include the first character of the column you are searching for, then a table scan is performed.

If possible, you should avoid using the SUBSTRING function and use the LIKE condition instead, for better performance.

Instead of doing this:

WHERE SUBSTRING(column_name,1,1) = 'b'

Try using this instead:

WHERE column_name LIKE 'b%'

If you decide to make this choice, keep in mind that you will want your LIKE condition to be sargable, which means that you cannot place a wildcard in the first position. [6.5, 7.0, 2000] Updated 3-20-2006

*****

Where possible, avoid string concatenation in your Transact-SQL code, as it is not a fast process, contributing to overall slower performance of your application. [6.5, 7.0, 2000] Updated 8-7-2006

*****

Generally, avoid using optimizer hints in your WHERE clauses. This is because it is generally very hard to outguess the Query Optimizer. Optimizer hints are special keywords that you include with your query to force how the Query Optimizer runs. If you decide to include a hint in a query, this forces the Query Optimizer to become static, preventing the Query Optimizer from dynamically adapting to the current environment for the given query. More often than not, this hurts, not helps performance.

If you think that a hint might be necessary to optimize your query, be sure you do all of the following first:

  • Update the statistics on the relevant tables.
  • If the problem query is inside a stored procedure, recompile it.
  • Review the search arguments to see if they are sargable, and if not, try to rewrite them so that they are sargable.
  • Review the current indexes, and make changes if necessary.

If you have done all of the above, and the query is not running as you expect, then you may want to consider using an appropriate optimizer hint.

If you haven't heeded my advice and have decided to use some hints, keep in mind that as your data changes, and as the Query Optimizer changes (through service packs and new releases of SQL Server), your hard-coded hints may no longer offer the benefits they once did. So if you use hints, you need to periodically review them to see if they are still performing as expected. [6.5, 7.0, 2000] Updated 8-7-2006

*****

If you have a WHERE clause that includes expressions connected by two or more AND operators, SQL Server will evaluate them from left to right in the order they are written. This assumes that no parenthesis have been used to change the order of execution. Because of this, you may want to consider one of the following when using AND:

  • Locate the least likely true AND expression first. This way, if the AND expression is false, the clause will end immediately, saving time.
  • If both parts of an AND expression are equally likely being false, put the least complex AND expression first. This way, if it is false, less work will have to be done to evaluate the expression.

You may want to consider using Query Analyzer to look at the execution plans of your queries to see which is best for your situation. [6.5, 7.0, 2000] Updated 8-7-2006

*****

If you want to boost the performance of a query that includes an AND operator in the WHERE clause, consider the following:

  • Of the search criterions in the WHERE clause, at least one of them should be based on a highly selective column that has an index.
  • If at least one of the search criterions in the WHERE clause is not highly selective, consider adding indexes to all of the columns referenced in the WHERE clause.
  • If none of the column in the WHERE clause are selective enough to use an index on their own, consider creating a covering index for this query.

[7.0, 2000] Updated 8-7-2006

*****

The Query Optimizer will perform a table scan or a clustered index scan on a table if the WHERE clause in the query contains an OR operator and if any of the referenced columns in the OR clause are not indexed (or does not have a useful index). Because of this, if you use many queries with OR clauses, you will want to ensure that each referenced column in the WHERE clause has a useful index. [7.0, 2000] Updated 8-7-2006

*****

A query with one or more OR clauses can sometimes be rewritten as a series of queries combined with a UNION ALL statement in order to boost the performance of the query. For example, let's take a look at the following query:

SELECT employeeID, firstname, lastname
FROM names
WHERE dept = 'prod' or city = 'Orlando' or division = 'food'

This query has three separate conditions in the WHERE clause. In order for this query to use an index, then there must be an index on all three columns found in the WHERE clause.

This same query can be written using UNION ALL instead of OR, like this example:

SELECT employeeID, firstname, lastname FROM names WHERE dept = 'prod'
UNION ALL
SELECT employeeID, firstname, lastname FROM names WHERE city = 'Orlando'
UNION ALL
SELECT employeeID, firstname, lastname FROM names WHERE division = 'food'

Each of these queries will produce the same results. If there is only an index on dept, but not the other columns in the WHERE clause, then the first version will not use any index and a table scan must be performed. But the second version of the query will use the index for part of the query, not for all of the query.

Admittedly, this is a very simple example, but even so, it does demonstrate how rewriting a query can affect whether or not an index is used or not. If this query was much more complex, then the approach of using UNION ALL might be must more efficient, as it allows you to tune each part of the index individually, something that cannot be done if you use only ORs in your query.

Note that I am using UNION ALL instead of UNION. The reason for this is to prevent the UNION statement from trying to sort the data and remove duplicates, which hurts performance. Of course, if there is the possibility of duplicates, and you want to remove them, then of course you can use just UNION.

If you have a query that uses ORs and it not making the best use of indexes, consider rewriting it as a UNION ALL, and then testing performance. Only through testing can you ensure one version of your query will be faster than another. [7.0, 2000] Updated 8-7-2006

*****

Don't use ORDER BY in your SELECT statements unless you really need to, as it adds a lot of extra overhead. For example, perhaps it may be more efficient to sort the data at the client than at the server. In other cases, perhaps the client doesn't even need sorted data to achieve its goal. The key here is to remember that you shouldn't automatically sort data, unless you know it is necessary. [6.5, 7.0, 2000] Updated 8-7-2006

*****

Whenever SQL Server has to perform a sorting operation, additional resources have to be used to perform this task. Sorting often occurs when any of the following Transact-SQL statements are executed:

  • ORDER BY.
  • GROUP BY.
  • SELECT DISTINCT.
  • UNION.
  • CREATE INDEX (generally not as critical as happens much less often).

In many cases, these commands cannot be avoided. On the other hand, there are few ways that sorting overhead can be reduced. These include:

  • Keep the number of rows to be sorted to a minimum. Do this by only returning those rows that absolutely need to be sorted.
  • Keep the number of columns to be sorted to the minimum. In other words, don't sort more columns that required.
  • Keep the width (physical size) of the columns to be sorted to a minimum.
  • Sort column with number datatypes instead of character datatypes.

When using any of the above Transact-SQL commands, try to keep the above performance-boosting suggestions in mind. [6.5, 7.0, 2000] Updated 3-20-2006

*****

If you have to sort by a particular column often, consider making that column a clustered index. This is because the data is already presorted for you and SQL Server is smart enough not to resort the data. [6.5, 7.0, 2000] Updated 2-19-2007

*****

If your WHERE clause includes an IN operator along with a list of values to be tested in the query, order the list of values so that the most frequently found values are placed at the first of the list, and the less frequently found values are placed at the end of the list. This can speed performance because the IN option returns true as soon as any of the values in the list produce a match. The sooner the match is made, the faster the query completes. [6.5, 7.0, 2000] Updated 10-16-2006

*****

If your SELECT statement contains a HAVING clause, write your query so that the WHERE clause does most of the work (removing undesired rows) instead of the HAVING clause do the work of removing undesired rows. Using the WHERE clause appropriately can eliminate unnecessary rows before they get to the GROUP BY and HAVING clause, saving some unnecessary work, and boosting performance.

For example, in a SELECT statement with WHERE, GROUP BY, and HAVING clauses, here's what happens. First, the WHERE clause is used to select the appropriate rows that need to be grouped. Next, the GROUP BY clause divides the rows into sets of grouped rows, and then aggregates their values. And last, the HAVING clause then eliminates undesired aggregated groups. If the WHERE clause is used to eliminate as many of the undesired rows as possible, this means the GROUP BY and the HAVING clauses will have less work to do, boosting the overall performance of the query. [6.5, 7.0, 2000] Updated 10-16-2006

*****

If your application performs many wildcard (LIKE %) text searches on CHAR or VARCHAR columns, consider using SQL Server's full-text search option. The Search Service can significantly speed up wildcard searches of text stored in a database. [7.0, 2000] Updated 10-16-2006

*****

The GROUP BY clause can be used with or without an aggregate function. But if you want optimum performance, don't use the GROUP BY clause without an aggregate function. This is because you can accomplish the same end result by using the DISTINCT option instead, and it is faster.

For example, you could write your query two different ways:

USE Northwind
SELECT OrderID
FROM [Order Details]
WHERE UnitPrice > 10
GROUP BY OrderID

Or,

USE Northwind
SELECT DISTINCT OrderID
FROM [Order Details]
WHERE UnitPrice > 10

Both of the above queries produce the same results, but the second one will use fewer resources and perform faster. [6.5, 7.0, 2000] Updated 2-5-2007

*****

The GROUP BY clause can be sped up if you follow these suggestions:

  • Keep the number of rows returned by the query as small as possible.
  • Keep the number of groupings as few as possible.
  • Don't group redundant columns.
  • If there is a JOIN in the same SELECT statement that has a GROUP BY, try to rewrite the query to use a subquery instead of using a JOIN. If this is possible, performance will be faster. If you have to use a JOIN, try to make the GROUP BY column from the same table as the column or columns on which the set function is used.
  • Consider adding an ORDER BY clause to the SELECT statement that orders by the same column as the GROUP BY. This may cause the GROUP BY to perform faster. Test this to see if is true in your particular situation.

[7.0, 2000] Updated 2-5-2007

*****

Sometimes perception is more important that reality. For example, which of the following two queries is the fastest?

  • A query that takes 30 seconds to run, and then displays all of the required results.
  • A query that takes 60 seconds to run, but displays the first screen full of records in less than 1 second.

Most DBAs would choose the first option as it takes less server resources and performs faster. But from many users' point-of-view, the second one may be more palatable. By getting immediate feedback, the user gets the impression that the application is fast, even though in the background, it is not.

If you run into situations where perception is more important than raw performance, consider using the FAST query hint. The FAST query hint is used with the SELECT statement using this form:

OPTION(FAST number_of_rows)

Where number_of_rows is the number of rows that are to be displayed as fast as possible.

When this hint is added to a SELECT statement, it tells the Query Optimizer to return the specified number of rows as fast as possible, without regard to how long it will take to perform the overall query. Before rolling out an application using this hint, I would suggest you test it thoroughly to see that it performs as you expect. You may find out that the query may take about the same amount of time whether the hint is used or not. If this is the case, then don't use the hint. [7.0, 2000] Updated 2-5-2007

*****

It is fairly common to write a Transact-SQL query to compare a parent table and a child table and find out if there are any parent records that don't have a match in the child table. Generally, this can be done three ways:

Using a NOT EXISTS:

SELECT a.hdr_key
FROM hdr_tbl a
WHERE NOT EXISTS (SELECT * FROM dtl_tbl b WHERE a.hdr_key = b.hdr_key)

Using a LEFT JOIN:

SELECT a.hdr_key
FROM hdr_tbl a
LEFT JOIN dtl_tbl b ON a.hdr_key = b.hdr_key
WHERE b.hdr_key IS NULL

Using a NOT IN:

SELECT hdr_key
FROM hdr_tbl
WHERE hdr_key NOT IN (SELECT hdr_key FROM dtl_tbl)

In each case, the above query will return identical results. But which of these three variations of the same query produces the best performance? Assuming everything else is equal, the best performing version through the worst performing version will be from top to bottom, as displayed above. In other words, the NOT EXISTS variation of this query is generally the most efficient.

I say generally because the indexes found on the tables, along with the number of rows in each table, can influence the results. If you are not sure which variation to try yourself, you can try them all and see which produces the best results in your particular circumstances. [7.0, 2000] Updated 2-19-2007

*****

Be careful when using OR in your WHERE clause, as it is fairly simple to accidentally retrieve much more data than you need, which hurts performance. For example, take a look at the query below:

SELECT companyid, plantid, formulaid
FROM batchrecords
WHERE companyid = '0001' and plantid = '0202' and formulaid = '39988773'
OR
companyid = '0001' and plantid = '0202'

As you can see from this query, the WHERE clause is redundant, as

companyid = '0001' and plantid = '0202' and formulaid = '39988773'

is a subset of

companyid = '0001' and plantid = '0202'

In other words, this query is redundant. Unfortunately, the SQL Server query optimizer isn't smart enough to know this, and will do exactly what you tell it to. What will happen is that SQL Server will have to retrieve all the data you have requested, then in effect do a SELECT DISTINCT to remove redundant rows it unnecessarily finds.

In this case, if you drop this code from the query

OR
companyid = '0001' and plantid = '0202'

then run the query, you will receive the same results, but with much faster performance. [6.5, 7.0, 2000] Updated 2-19-2007

*****

Avoid using variables in the WHERE clause of a query located in a batch file. Let's find out why this may not be a good idea.

First, let's look at the following code:

SELECT employee_id
FROM employees
WHERE age = 30 and service_years = 10

Assuming that both the age and the service_years columns have indexes, and the table has many thousands of records, then SQL Server's query optimizer will select the indexes to perform the query and return results very quickly.

Now, let's look at the same query, but written to be more generic, one that you might find in a generic batch file:

DECLARE @age int
SET @age = "30"
DECLARE @service_years int
SET @service_years = "10"
SELECT employee_id
FROM employees
WHERE age = @age and service_years = @service_years

When the above code is run, even though both the age and the service_years columns have indexes, they may not be used, and a table scan may be used instead, potentially greatly increasing the amount of time for the query to run.

The reason the indexes may not be used is because the Query Analyzer does not know the value of the variables when it selects an access method to perform the query. Because this is a batch file, only one pass is made of the Transact-SQL code, preventing the Query Optimizer from knowing what it needs to know in order to select an access method that uses the indexes.

If you cannot avoid using variables in the WHERE clauses of batch scripts, consider using an INDEX query hint to tell the query optimizer to use the available indexes instead of ignoring them and performing a table scan. If, of course, the indexes are highly selective. If the indexes are not highly selective, then a table scan most likely will be more efficient than using the available indexes.

Another option is not to use a script, but a stored procedure instead. Variables in stored procedures don't cause the problem described above. [6.5, 7.0, 2000] Updated 2-19-2007

Have a 'weird' friend

Hi guys ,


i have friend but i think he is a gay. im really disguisting but i dunno how i can go away from him. i aleready try anything to make him go away to my life but he dont give up. tell me what should i do ?

My first posting

This is my 1st post

Test