Friday, October 30, 2009

Navigation to the webpage was canceled

For many years, SQL Anywhere has used Microsoft Compiled HTML Help files (*.chm) to deliver all the manuals in one easy-to-read, easy-to-search package on your desktop, one that doesn't make you wander through endless menus and wait for slow-loading web pages.

These files are easy to copy, too, and sometimes folks copy the Help files from machine to machine without using the official SQL Anywhere setup.exe... and they zip them up and send them by email as well.

Suddenly, however, that process has become fraught with error: On the receiving end, when you open the *.chm file, you get "Navigation to the webpage was canceled" no matter which topic you navigate to:



Steven McDowell has the answer (and by the way, the problem DOES NOT AFFECT files installed by the official setup):


from Steven McDowell
to Breck Carter
date Wed, Oct 28, 2009 at 5:11 PM
subject Files downloaded from our FTP site can be "blocked" on XP/Vista/Win 7

Hi Breck,

FYI ... my investigation of your "blocked" CHMs seems to have determined what is going on.

Steve

It appears that a recent Windows security update may have further restricted the use of CHM files on XP and Vista. I don't know if other file types are affected by this, but I thought I would share the info since we often ZIP files and send them via FTP to customers and other staff.

Sneak peak: It actually appears to be an IE "feature". That's all you get here. See conclusion at bottom. :-)

It was reported that our CHM docs failed to open on an XP computer. The CHMs had been zipped here and copied via FTP. When they were unzipped, they were marked as "blocked" and the contents could not be viewed until each file was unblocked.

I have reproduced the problem on my Windows 7 system. I am an administrator but still have UAC turned on. Here is what I encountered:
* Unzipping to a local temp folder proceeds normally.
* When I try to open one of the CHMs, I get:
* If I leave the "Always ask" checkbox checked and click Open, the CHM opens, but the contents pane is blocked (with an unhelpful message). This behaviour is the same as trying to open a CHM from a network drive, but this is happening on a local drive.

* As long as the "Always ask" checkbox is checked, the contents pane is blocked for that file regardless of how many times you try to open it. Once I uncheck the box and click Open, not one but two things happen: 1) the contents pane is visible, and, 2) the dialog no longer appears. So something in the file's attributes has changed permanently.

* I picked another CHM file that had not been opened yet. I displayed its Properties. Note the Unblock button and the text to the left. This button and text are not displayed in the Properties for CHMs that were opened with the checkbox turned off. So, the "Always ask" checkbox has the dual purpose of suppressing the dialog and marking the file as unblocked.


Fortunately, it appears that using our doc install does not trigger this blocking problem. There is the possibility that other file types sent via ZIP (and probably other file copy methods) will also encounter these issues.

I did find one discussion (in the social.msdn.microsoft.com link below) that suggests it is IE that is noting that the files came from "the Internet" and marking them as blocked. I'm not sure how that works inside a ZIP file, but it appears to. Possibly non-IE transfers will not do this. CONFIRMED! I downloaded the same ZIP file via FTP using Firefox instead of IE and the files are not blocked!

Relevant URLs (Google "windows chm file blocked"):

http://support.microsoft.com/kb/896054/
http://support.microsoft.com/kb/902225
http://www.drexplain.com/press/chm-files-the-page-cannot-be-displayed-error/
http://social.msdn.microsoft.com/Forums/en-US/windowscompatibility/thread/6393365a-272e-4da2-9cd1-c3b63f4929b4

Steve

Wednesday, October 28, 2009

Comparing Database Schemas, Improved Edition

The original version of this article contained this false statement: "These dbunload steps ... only work on Version 10 and 11 databases ..."

Well, not exactly false, but easily fixed so the technique will work on earlier database files: Versions 5.5, 6, 7, 8 and 9. It turns out that while the Version 11 engine can't run a Version 9 database file, that restriction does not apply to the dbunload utility. In order to facilitate database migrations, dbunload contains the ability to read earlier database files... and that ability extends to ordinary dbunload-to-a-SQL-file steps.

And that bit of magic makes it possible to compare all versions of databases. Here's the full rewrite of the original article:



Question: How do I compare the schemas of two SQL Anywhere databases?

Answer, from Bruce Hay at Sybase iAnywhere: Check out the new "-no" option for dbunload in SQL Anywhere 11 (unload objects in name order, no data)? It's intended for this purpose.



Here's how it works:
  • Step 1: Run dbunload against the first SQL Anywhere database to create a text file containing CREATE TABLE and other schema definitions. The new -no option tells dbunload to unload just the schema, not the data, and do it in name order so it will be easier to compare with another text file sorted in the same order.

  • Step 2: Run dbunload again, on the second SQL Anywhere database, to produce another text file.

  • Step 3: Run a text comparison utility like Compare It! to show the differences between the two text files.
[ Keep reading, the new stuff is coming soon... ]
Here's why using dbunload is a good approach:
  • The dbunload utility doesn't miss anything; it unloads every single schema object in the database... tables, views, procedures, triggers, everything.

  • The dbunload utility is always going to be more up-to-date than any other software except the SQL Anywhere engine itself. In other words, even PowerDesigner falls behind dbunload in terms of supporting SQL Anywhere syntax for new features.

  • Running dbunload on actual databases guarantees you will be comparing the current database schemas, not out-of-date information stored is separate model files.

  • The text file comparison view presents differences in terms of actual database syntax, not some funky abstract logical view used by data modelling tools.
[ OK, here comes the new stuff... ]

But Wait! It's Not Quite That Easy!


How you code the "Run dbunload" parts of Steps 1 and 2 depends on what version of SQL Anywhere was used to create each database:
  • If the database was created with Version 5.5, 6, 7, 8 or 9 you have to run the Version 11 copy of dbunload.exe without starting the database first. Use the -c "DBF=filespec.db;UID=xxx;PWD=yyy" connection string so that the Version 9 engine inside dbunload.exe will be used to start the database. Yes, this is magic!

  • If the database was created with Version 10 or 11, you do have to start the database first, using the Version 11 engine dbeng11.exe or dbsrv11.exe, and then run the Version 11 copy of dbunload.exe with the usual client-server connection string -c "ENG=aaa;DBN=bbb;UID=xxx;PWD=yyy".
That's not just magic, it's also complicated and confusing. That's why I've created three examples you can copy and edit: Compare Version 10 and 11 databases using the second technique described above, then Version 5.5 with Version 9 using the first technique, and finally Version 5.5 with Version 11 using both techniques. These examples all use the demo databases that come with the various versions of SQL Anywhere.

Example 1: Compare Version 10 and 11 Database Schemas


This script is easily changed to work with two Version 10 databases, or two Version 11 databases.

compare_demo10_demo11.bat
REM Start V10 database via V11 engine

"%SQLANY11%\bin32\dbspawn.exe"^
-f^
"%SQLANY11%\bin32\dbeng11.exe"^
-n demo10^
"C:\Documents and Settings\All Users\Documents\SQL Anywhere 10\Samples\demo.db"

PAUSE

REM Unload V10 database

"%SQLANY11%\Bin32\dbunload.exe"^
-c "ENG=demo10;DBN=demo;UID=dba;PWD=sql"^
-no^
-r c:\temp\demo10.sql

PAUSE

REM Start V11 database

"%SQLANY11%\bin32\dbspawn.exe"^
-f^
"%SQLANY11%\Bin32\dbeng11.exe"^
-n demo11^
"C:\Documents and Settings\All Users\Documents\SQL Anywhere 11\Samples\demo.db"

PAUSE

REM Unload V11 database

"%SQLANY11%\Bin32\dbunload.exe"^
-c "ENG=demo11;DBN=demo;UID=dba;PWD=sql"^
-no^
-r c:\temp\demo11.sql

PAUSE

REM Compare schemas

"C:\Program Files\Compare It!\wincmp3.exe"^
c:\temp\demo10.sql^
c:\temp\demo11.sql

PAUSE
Here's what Compare It! shows for one difference:



Compare It! can also produce a report in HTML format; just use File - Report... to get output like this:



Example 2: Compare Version 5.5 and 9 Database Schemas


This script is easily changed to work with two Version 9 databases, or any combination of Version 5.5 through 9.

compare_demo5_demo9.bat
REM Start and unload V5 database via V11 dbunload

"%SQLANY11%\Bin32\dbunload.exe"^
-c "DBF=C:\Program Files\Sybase\SQL Anywhere 5.0\sademo.db;UID=dba;PWD=sql"^
-no^
-r c:\temp\demo5.sql

PAUSE

REM Start and unload V9 database via V11 dbunload

"%SQLANY11%\Bin32\dbunload.exe"^
-c "DBF=C:\Program Files\Sybase\SQL Anywhere 9\asademo.db;UID=dba;PWD=sql"^
-no^
-r c:\temp\demo9.sql

PAUSE

REM Compare schemas

"C:\Program Files\Compare It!\wincmp3.exe"^
c:\temp\demo5.sql^
c:\temp\demo9.sql

PAUSE

Here's a Compare It! screen shot:



Example 3: Compare Version 5.5 and 11 Database Schemas


This script is easily changed to compare a Version 5.5 through 9 database with a Version 10 or 11 database.

compare_demo5_demo11.bat
REM Start and unload V5 database via V11 dbunload

"%SQLANY11%\Bin32\dbunload.exe"^
-c "DBF=C:\Program Files\Sybase\SQL Anywhere 5.0\sademo.db;UID=dba;PWD=sql"^
-no^
-r c:\temp\demo5.sql

PAUSE

REM Start V11 database

"%SQLANY11%\bin32\dbspawn.exe"^
-f^
"%SQLANY11%\Bin32\dbeng11.exe"^
-n demo11^
"C:\Documents and Settings\All Users\Documents\SQL Anywhere 11\Samples\demo.db"

PAUSE

REM Unload V11 database

"%SQLANY11%\Bin32\dbunload.exe"^
-c "ENG=demo11;DBN=demo;UID=dba;PWD=sql"^
-no^
-r c:\temp\demo11.sql

PAUSE

"C:\Program Files\Compare It!\wincmp3.exe"^
c:\temp\demo5.sql^
c:\temp\demo11.sql

PAUSE

This Compare It! screen shot shows where the schema starts to diverge; after this point, everything's different between the Version 5.5 and 11 demo databases:

Monday, October 26, 2009

DocCommentXchange 2.0 Rocks!



I will let Laura Nevin, Shengyu Bao, Andrew Arnott and Steven McDowell tell the story:

From: Steven.McDowell@sybase.com
Sent: Friday, October 23, 2009 11:54 AM
Subject: DocCommentXchange 2.0 is now live

Hi Breck,

I think this is what you have been waiting for. It took way longer than expected, but I think the internal improvements were worth the wait.

Please email me if you have any problems or issues, or even comments about DCX.

Steve

----- Forwarded by Steven McDowell/SYBASE on 10/23/2009 11:53 AM -----

DocCommentXchange 2.0 is now running at dcx.sybase.com.

Main new features:
* based on SA11 web server and full text search (no Apache or PHP)
* preview area added to "Submit a comment" dialog; your comment is formatted and displayed while you type
* index is much faster now
* bookmarks for pages are more readable
Other notes:
* existing URLs remain valid
* existing comments are preserved
* existing userids remain valid
Steve, Laura, Andrew, Shengyu

Friday, October 23, 2009

How To Capture A Graphical Plan

(Updated August 3, 2012 to include Version 12, plus a screenshot of the Plan Viewer.)


Graphical plans are wonderful things. Graphical plans tell you everything you need to know about why a query is running slowly.

Even if you don't have a clue about how to read a graphical plan, it's still wonderful because you can capture it in a file and send it to someone who does know how to read it ( like Glenn Paulley ) or someone like [cough] who pretends to know :)

Seriously, let's say you have The Query From Hell, some SELECT that's taking forever. Maybe yesterday (on SQL Anywhere 9) it ran quickly but now (on SQL Anywhere 11) it runs like continental drift... or whatever, it's slow now.

Here are the steps for capturing the graphical plan, for Versions 8 through 12. At the bottom there's a "Tip" that is very important, but only for Version 10 and earlier.

How To Capture A Graphical Plan In Version 11 and 12

- If desired, run CALL sa_flush_cache() in dbisql.

- Type or paste your query into dbisql.

- Choose Tools - Plan Viewer.

- Select Statisics level: Detailed and node statistics.

- Select Cursor type: Asensitive.

- Select Update status: Read-only.

- Click "Get Plan".

- When the plan appears, click "Save As...".

- Use Save as type Execution plan (*.saplan).

Click on this screenshot to see it full size...


How To Capture A Graphical Plan In Version 10

- In dbisql, choose Tools - Options... - Plan.

- Check "Graphical plan with full statistics".

- Check "Assume read-only cursor" if that applies.

- Pick "Assume cursor is: Asensitive" if that applies.

- Click "OK".

- Run CALL sa_flush_cache() if desired.

- Run your query (see Tip below).

- Do File - Save As - Save as type: XML (*.xml).

How To Capture A Graphical Plan In Version 9

- In dbisql, choose Tools - Options... - Plan.

- Check "Graphical plan with statistics".

- Check "Assume read-only cursor" if that applies.

- Pick "Assume cursor is: Asensitive" if that applies.

- Click "Make Permanent".

- Run CALL sa_flush_cache() if desired.

- Run your query (see Tip below).

- Do File - Save As - Save as type: XML (*.xml).

How To Capture A Graphical Plan In Version 8

- In dbisql, choose Tools - Options... - Plan.

- Check "Graphical plan with statistics".

- Check "Assume read-only cursor" if that applies.

- Pick "Assume cursor is: Asensitive" if that applies.

- Uncheck "Show UltraLite plan" unless you want that.

- Click "Make Permanent".

- Run CALL sa_flush_cache() if desired.

- Run your query (see Tip below).

- Do File - Save As - Save as type: XML (*.xml).

Tip for Version 10 and earlier: If you do use dbisql to execute a query and capture a graphical plan with statistics, use SQL - Get Plan (Shift+F5) instead of SQL - Execute (F5 or F9). If you use Execute, the query will be executed twice: once to determine the result set and a second time to capture the plan. This plan may be completely different from the one used the first time the query was executed, and not just because the cache contains the rows. For example, if the plan is for a DELETE, the first execution will actually delete the rows so the plan may be for the completely different "zero rows" case. If you use Get Plan (Shift+F5) the query will only be run once, and the plan will match.

Monday, October 19, 2009

"Search this blog, plus 5 others..."

The Google Custom Search Engine gadgets on this page have changed:



First of all, the original Search gadget has been changed from "Search this blog, plus Glenn Paulley's" to "Search this blog, plus 5 others": Glenn's plus the other four active SQL Anywhere blogs on iablog.sybase.com: Jason Hinsperger, Chris Kleisath, Eric Farrar and Tom Slee.

Second, a new gadget "Search this blog" has been added. This one is an "ego search", just for me, so I can search my old posts.

Third, the additional gadget uses the new Google "Custom Search Element" which displays the result set in an overlay on the same page instead of jumping to a separate search page:



Yeah, that's confusing: "Custom Search Element" sounds so much like "Custom Search Engine"... perhaps Google is taking steps to preserve the earth's rapidly diminishing supply of acronyms.

Friday, October 16, 2009

Product Futures: Grow In-Memory Cache Faster

Maybe I've been living a sheltered life, but until recently I've never seen SQL Anywhere have a Cache Panic. Not once, not in production, not in testing, not even while testing Foxhound which is supposed to display the number of Cache Panics on the monitor page.

What is a Cache Panic? It happens when SQL Anywhere needs to allocate a page in the cache but can't find one. Sounds bad, but what with dynamic cache sizing and the temporary file, I'd never seen one.

At one point, I considered removing Cache Panics from the Foxhound monitor page to save valuable screen real estate (if you've seen the Foxhound monitor page, you know what "crowded" means when it comes to displays :) However, a wise voice counseled me to leave it alone, saying that it's an important statistic.

Not important enough, however, for me to include a Cache Panics threshold in the Foxhound email alerts feature... that was a bad decision, about to be fixed... because I've just seen my first Cache Panics, and believe me, they are bad:



What the Foxhound figures above don't show is how badly performance can be affected when Cache Panics are happening. When you start a SQL Anywhere database using the in-memory feature (dbsrv11 -im nw in this case), there is no temporary file, and it doesn't write anything to the database file, so SQL Anywhere has no place other than RAM to put a page of data. If the RAM cache is full, SQL Anywhere has to allocate more RAM.

It gets worse: If you don't specify the -c initial RAM cache size value when you start the server, and if you perform some intense operation like LOAD TABLE a million rows, SQL Anywhere will have to allocate RAM at a furious pace... all the while Cache Panicking when it can't find a page to allocate.

Who cares? If performance is important, you care. In this case adding -c 1200M to the dbsrv11 command line improved LOAD TABLE performance by 165%, from 2,878 rows per second to 7,640 rows per second.

Grow In-Memory Cache Faster

Here's what the server console log looked like when it had to grow the cache a zillion times, up to 10 times per second:

I. 10/14 15:29:15. Now accepting requests
I. 10/14 15:29:18. Cache size adjusted to 2340K
I. 10/14 15:29:23. Cache size adjusted to 3180K
I. 10/14 15:29:28. Cache size adjusted to 3392K
I. 10/14 15:29:33. Cache size adjusted to 3488K
I. 10/14 15:30:14. DIAG 2009-10-14 15:30:14.421 load table started
I. 10/14 15:30:14. Cache size adjusted to 3748K
I. 10/14 15:30:14. Cache size adjusted to 4012K
I. 10/14 15:30:14. Cache size adjusted to 4276K
...
I. 10/14 15:41:23. Cache size adjusted to 1151416K
I. 10/14 15:41:23. Cache size adjusted to 1151676K
I. 10/14 15:41:23. Cache size adjusted to 1151936K
I. 10/14 15:41:23. Cache size adjusted to 1151724K
I. 10/14 15:41:23. Cache size adjusted to 1152144K
I. 10/14 15:41:23. Cache size adjusted to 1152404K
I. 10/14 15:41:24. Cache size adjusted to 1152668K
I. 10/14 15:41:24. DIAG 2009-10-14 15:41:24.343 load table finished in 669.0 seconds
I. 10/14 15:42:23. Cache size adjusted to 1152388K
I. 10/14 15:42:27. Cache size adjusted to 1152800K

Most of the time, growing the cache step-by-step works just fine... but not when the database is growing rapidly and it's all stored in memory.

The Suggestion...

So here's the Product Futures suggestion: When a SQL Anywhere database is running in-memory, and a lot of Cache Panics are happening, and it's having to grow the cache ten times a second, then the dynamic cache sizing algorithm should pick some increment other than 64 pages when allocating more RAM.

That way, we won't have to fiddle around trying to pick exactly the right -c initial cache size.

...Or, Maybe Not

It's a little known fact (well, I didn't know it) that picking a reasonable value for -c is a good idea regardless of the cache growth performance issue described here.

For example, if you expect the cache to grow to some size between 1G and 2G, you should specify a value like -c 1G instead of letting it default to the tiny value (on Windows) of 2M. The server uses hash chains to find data in the cache, and the number of hash chains is determined by the initial cache size. A cache that starts at 2M will have fewer hash chains and those chains will grow very long (and slow) as the cache grows to 2G; performance will suffer, even if the Cache Panics problem is solved. And that performance problem will persist even after the cache finishes growing.

On the other hand, a cache that starts at -c 1G and grows to 2G will have more, shorter chains, and better performance. In other words, you don't have to pick an exact value for -c, but you should avoid letting it default to a stup..., er, wildly inappropriate value (like 2M) if you know it's going to grow to at least 1G.

And, of course, the Cache Panics problem won't be nearly so noticeable if you pick a half-decent value for -c. Plus, it goes away after the cache finishes growing.

So, maybe it's not worth fixing, just worth knowing about :)

Wednesday, October 14, 2009

SQL Anywhere Product Futures Discussion

Sybase forum users will recognize "SQL Anywhere Product Futures Discussion" as the title for the sybase.public.sqlanywhere.product_futures_discussion newsgroup on the forums.sybase.com NNTP server. It's available from your web browser, but I won't put a link here because every one of the several HTTP / HTML interfaces to the NNTP forums are, well, inadequate.

Besides, the NNTP forums are reaching the end of their usefulness, which is why I'm not going to post suggestions there any more... I'm going to post them here, starting now...

DB_PROPERTY ( 'BackupInProgress' )

There should be a database property which answers the question, "Is a database backup process in progress?" It would apply to the BACKUP statement and the dbbackup.exe utility.

The question arises, should the answer be as simple as yes/no, or more complex? The continuous live backup process comes to mind, where the answer would always be yes... maybe live backups should be excluded.

And what about database versus log-only backups? Should the response be db/log/both/no?

That's what "discussion" is for; if you have an opinion, post a comment here.

One reason for having this property is so database monitor programs, like Foxhound and the SQL Anywhere Monitor, could adjust their behavior when a backup is running; e.g., they could recognize that server I/O processing will change in behavior, and that checkpoints will be suspended.

Another reason might be so you can write code that starts a backup as long as one isn't running already, perhaps a second redundant process that makes sure a backup is taken even if some other backup process failed.

DB_PROPERTY ( 'BackupSuccessfulAt' )

This database property should answer the question, "When was the last backup taken?" It should return NULL if there never has been a successful backup, or the timestamp when the most recent successful backup finished.

In my opinion, this request doesn't need any justification... it's hard to think of any question more important than one involving database backups. And today, there is just no reliable way to answer the question, certainly not easily.

I'm guessing live backups don't count here, if only because then never finish unless there's a problem; e.g., the server crashes, so dbbackup loses connectivity... and a database property is useless if the server ain't running.

Should there be different properties for different backup types? e.g., 'DBBackupSuccessfulAt', 'LogBackupSuccessfulAt', 'FullBackupSuccessfulAt'... more discussion!

Monday, October 12, 2009

Global Exception Handler

Stephan.ahlf posted an excellent suggestion in this thread in the Google SQL Anywhere Web Development group:

"It would be a nice feature if developers could implement a Global Exception Handler. In case of errors in procedures invoked via a database event there is only a error message in the database console. With a Global Exception Handler I could develop a general error notification e.g via email. There is an event for after RAISEERROR. Does there exists somthing like that for native database exceptions?"
Eric Farrar thinks it's a good idea too, which is wonderful news; Eric is highly respected throughout the SQL Anywhere community and his word should carry some significant weight:
"Unfortunately, there is nothing inside of SQL Anywhere to allow you to specify a top-level exception handler that will be called on any native database exception. I do understand why this would be useful (especially in a web context), and I have passed this idea on to the appropriate engineers."
Exception handling plays a huge role in the web-based Foxhound database monitor, and I would love to be able to code an all-encompassing global exception handler to record errors for later diagnosis.

One problem facing a global exception handler, however, is providing an answer to the question "Where, in all the thousands of lines of SQL code, did this exception occur?"

That's a hard question to answer even for a local exception handler. One solution (used by Foxhound) is to maintain a "where am I?" variable as the code executes just so an exception handler can include it with the other information it saves and/or displays.

For a global exception handler, one could use a global CREATE VARIABLE to store the "where am I?" value, but I would rather not... I would rather have SQL Anywhere provide the source code line number and object name (procedure, event, service, etc).

Sunday, October 11, 2009

We Don't Need No Steenking Backup!

Let's all welcome Microsoft and T-Mobile's Sidekick service as the latest Database Deadpool winners!

Here's the reported time line for the T-Mobile disaster:

Friday, October 2, 2009

Microsoft, whose Danger subsidiary powers the [T-Mobile] Sidekick service, said it is "working urgently" to deal with the problems, which interrupted data service for most Sidekick users starting at 1:30 a.m. PDT on Friday.
Major outage hits T-Mobile Sidekick users October 6, 2009 11:57 AM PDT by Ina Fried
We are working to resolve the issue and hope to have things restored to normal soon.
Sidekick Service Issue (Oct 2nd) 10-02-2009, 08:40 PM

Sunday, October 4, 2009

...it seems that Danger's data center has been on the fritz for a solid two days now with symptoms ranging from text message weirdness to dead address books and everything in between, up to and including a completely unusable experience. Frantic calls to T-Mobile are resulting in comped bills for some subscribers, so if you're affected, you might want to give 'em a ring.
Danger's server woes leave Sidekicks in the lurch by Chris Ziegler posted Oct 4th 2009 at 4:48PM

Monday, October 5, 2009

Users of T-Mobile's Sidekick smartphones spent much of the weekend without data service, and many are still waiting for service to be restored.
T-Mobile: Danger Working to Resolve Sidekick Data Outage Monday October 5, 2009

Thursday October 8, 2009

We sincerely apologize for the inconvenience, and appreciate your patience as Danger works hard, around-the-clock to resolve this issue. T-Mobile will continue to keep you updated as we learn more. Thank you!
Sidekick Service Issue 10-08-2009, 04:22 PM

Saturday, October 10, 2009

The massive data failure at Microsoft's Danger subsidiary threatens to put a dark cloud over the company's broader "software plus services" strategy.
Sidekick outage casts cloud over Microsoft October 10, 2009 3:26 PM PDT by Ina Fried
...this is shaping up to be one of the biggest disasters in the history of cloud computing.
T-Mobile: we probably lost all your Sidekick data by Chris Ziegler posted Oct 10th 2009 at 3:45PM
Perez Hilton loses 2000 contacts in his Sidekick. 2000 people to meet in Griffith Park for biggest group hug ever.
John Mayer
Regrettably, based on Microsoft/Danger's latest recovery assessment of their systems, we must now inform you that personal information stored on your device - such as contacts, calendar entries, to-do lists or photos - that is no longer on your Sidekick almost certainly has been lost as a result of a server failure at Microsoft/Danger.
T-MOBILE AND MICROSOFT/DANGER STATUS UPDATE ON SIDEKICK DATA DISRUPTIONUpdated: 10/10/2009 12:35 PM PDT
This is a code red cloud disaster.
Cloud Goes Boom, T-Mo Sidekick Users Lose All Data Posted by Eric Zeman, Oct 10, 2009 08:22 PM
This latest large-scale publicized data loss will surely lead to managers everywhere forwarding a link to the story to their IT departments asking "what are we doing so that this doesn't happen to us." ...
If you read almost any technology website or newspaper, you could be forgiven for thinking that "The Cloud" solves everything.
...
In the Danger case, it appears from initial speculation that the data was lost because they attempted to upgrade a storage array without backing it up first. Here is a case of smart and rational people who do this for a living at one of the best companies in the world, and they didn't even bother making a backup..
Letting Data Die A Natural Death Nik Cubrilovic TechCrunch.com Saturday, October 10, 2009; 8:20 PM

Sunday, October 11, 2009

Microsoft/Danger has stated that they cannot recover the data but are still trying.
Server Failure Destroys Sidekick Users' Backup Data Posted by timothy on Sunday October 11, @05:29AM

Wednesday, October 7, 2009

How To Make Sure Your DatabaseStart Event Finishes First

If you have scheduled events in your database, and those events contain logic that depends on the DatabaseStart event finishing beforehand, it's up to you to make sure your scheduled events don't start running too early.

For example, let's say you have critical initialization logic in your DatabaseStart event, and your scheduled events contain other logic that assumes the initialization process is complete before they run. Since every event runs on its own connection, and connections run asynchronously, there's no guarantee that the DatabaseStart event will finish before your scheduled events start firing.

One strategy is to add more logic to each scheduled event to check if the DatabaseStart event has finished running, and to immediately RETURN if DatabaseStart has not finished.

Here's one way to implement that strategy:

  • Add code to the end of the DatabaseStart event to record the CURRENT TIMESTAMP in a single-row table.

  • Add code to the beginning of each scheduled event to check if the SQL Anywhere server startup timestamp is later than the timestamp recorded by the DatabaseStart event.

  • If the server startup timestamp is later than the DatabaseStart timestamp, then RETURN from the scheduled event.
If the server startup timestamp is later than the DatabaseStart timestamp, then the DatabaseStart timestamp must have been recorded by a previous execution of the DatabaseStart event during a previous server startup... which in turn implies the DatabaseStart event for the current server startup hasn't finished executing.

Eventually, the DatabaseStart event will finish, and the next time the scheduled event fires it won't execute the RETURN.

Here are some excerpts from the Foxhound database monitor; first, a single-row table contains the DatabaseStart timestamp:

CREATE TABLE rroad_database_start_blocker (
one_row_only INTEGER NOT NULL DEFAULT 1
CHECK ( one_row_only = 1 )
PRIMARY KEY,
started_at TIMESTAMP NOT NULL );

CREATE TRIGGER trd_one_row_only BEFORE DELETE ON rroad_database_start_blocker
FOR EACH ROW
BEGIN
ROLLBACK TRIGGER WITH RAISERROR 99999 'Do not attempt to delete from rroad_database_start_blocker';
END;

INSERT rroad_database_start_blocker VALUES ( DEFAULT, CURRENT TIMESTAMP );
COMMIT;

Second, the DatabaseStart event updates DatabaseStart timestamp after all the initialization logic is complete:

CREATE EVENT rroad_database_start TYPE DatabaseStart HANDLER
BEGIN

... critical initialization code ...

------------------------------------------------------------------------
-- Block other events from proceeding until this event finishes.

UPDATE rroad_database_start_blocker
SET rroad_database_start_blocker.started_at = CURRENT TIMESTAMP
WHERE rroad_database_start_blocker.one_row_only = 1;

COMMIT;

END;

Finally, a scheduled event starts by checking the server startup timestamp against the DatabaseStart timestamp:

CREATE EVENT rroad_monitor_auto_restart
SCHEDULE START TIME '00:00' EVERY 10 SECONDS
DISABLE
HANDLER BEGIN

-- Wait for the rroad_database_start event to finish before proceeding.

IF COALESCE ( PROPERTY ( 'StartTime' ), '' ) = '' THEN

-- The SQL Anywhere engine hasn't yet filled in the StartTime property, so it can't be
-- compared with rroad_database_start_blocker.started_at, so it's not safe to proceed
-- with this event yet.

RETURN; -- try again when this event fires again

END IF;

IF CAST ( PROPERTY ( 'StartTime' ) AS TIMESTAMP )
> ( SELECT rroad_database_start_blocker.started_at
FROM rroad_database_start_blocker
WHERE rroad_database_start_blocker.one_row_only = 1 ) THEN

-- The DatabaseStart event hasn't yet updated rroad_database_start_blocker.started_at so
-- this event cannot proceed.

RETURN; -- try again when this event fires again

END IF;

... other logic that depends on the initialization process being complete ...

END;

Note that PROPERTY ( 'StartTime' ) might not even be filled in by the time a scheduled event starts executing so there are two reasons to RETURN early.

Friday, September 25, 2009

Quassnoi's Explain Extended

I've added a new blog to the "WIDER VIEWS..." list on the right: Quassnoi's Explain Extended.

Lot's of solid SQL content there, in particular this excellent discussion about "thinking in sets": Double-thinking in SQL.

Wednesday, September 23, 2009

Turning Off System Restore Points

I have discovered a new way to slow Microsoft SQL Server's BULK INSERT down so much that it mimics continental drift.

It's been a couple of years since the I discovered the first way to slow down BULK INSERT: leave the PRIMARY KEY and other indexes in place while inserting data. The solution to that problem is to drop all the indexes, run the BULK INSERT and then recreate the indexes... it can be orders of magnitude faster that way.

Why am I talking about BULK INSERT? Because SQL Server is often used together with SQL Anywhere, and it's often necessary to ship data back and forth between the two databases, and BULK INSERT is a very efficient technique... sometimes. The online docs do talk about Optimizing Bulk Import Performance, but the subject of indexes is mentioned only in passing: "How to best increase the performance of a particular bulk import operation is influenced by the following factors: ... Whether the table has indexes."
What's the new way to make BULK INSERT slow? Leave the Windows System Restore feature enabled on the disk drive holding the SQL Server database. That increases disk I/O enormously, and the I/O is split between two different files in two different locations on the same drive... thus making the head move back and forth, slowing things down much more than if only one file was affected.

I've never noticed this kind of disk activity before, perhaps because I haven't seen a display like the following until after installing Windows Vista with its wonderful Resource Monitor:



In the picture above you can see the heaviest write I/O involves a file in the C:\System Volume Information folder which is where Windows automatic restore points are recorded. The SQL Server database and log files (main.mdf and main.ldf) come second and third in terms of write I/O, and this ranking persists for the entire time the BULK INSERT is running.

And then there's all that database file read I/O... I'm guessing all of it is needed for the System Restore feature, as you'll see later when it all disappears.

The solution is to follow the instructions here and turn Windows System Restore off for the disk drive affected, as follows: Control Panel - System - System Protection - Automatic restore points - clear the checkbox next to the drive letter:



Turning off restore points made a dramatic difference in the BULK INSERT disk I/O, which in turn resulted in the elapsed time dropping from 1,612 seconds to 512 seconds for a 1.9 million row data set; that's a factor of 3 improvement. It did this by completely eliminating all I/O to the System Volume Information folder, which in turn allowed the database file I/O to run much faster. It also completely eliminated the database file read I/O as shown in this picture:



Does the Windows System Restore feature affect SQL Anywhere database? I'm not sure, but I think the answer is "no". I tried loading the same data into a SQL Anywhere 11 database via LOAD TABLE and there was no activity in the System Volume Information folder at all.

Oh, and I would love to tell you how much faster SQL Anywhere's LOAD TABLE was than BULK INSERT, but I can't... that would be a "benchmark test", a violation of the license agreements, and it might even exhibit some kind of "measurement bias"... who, me, biased? <g>

Wednesday, September 16, 2009

Compare Tables With UNLOAD INTO VARIABLE

Q: Let's say you have two tables where you think the data is identical; how do you compare them?

A: UNLOAD the tables and compare the resulting files.

Q: What if one of the tables is a proxy table? UNLOAD doesn't work on proxy tables.

A: Use SELECT * INTO #temp_table, then UNLOAD the temporary table.

Q: What if you want to do everything inside a SQL script, without running a separate "compare the files" step?

A: Use UNLOAD INTO VARIABLE and compare the variables with a SQL statement.

Here's an example showing both techniques, SELECT * INTO #temp_table and UNLOAD INTO VARIABLE, on a pair of proxy tables pointing to Microsoft SQL Server and SQL Anywhere databases:


BEGIN
DECLARE @sa_t LONG VARCHAR;
DECLARE @mss_t LONG VARCHAR;

SELECT *
INTO #mss_t
FROM proxy_mss_t;

SELECT *
INTO #sa_t
FROM proxy_sa_t;

UNLOAD TABLE #mss_t
INTO VARIABLE @mss_t;

UNLOAD TABLE #sa_t
INTO VARIABLE @sa_t;

SELECT IF @mss_t = @sa_t
THEN 'EQUAL'
ELSE 'NOT EQUAL'
ENDIF;
END;

Here's the output from dbisql:

if @mss_t = @sa_t then'EQUAL' else 'NOT EQUAL' endif
'EQUAL'

If you're working with local tables, you don't need the separate SELECT * INTO #temp_table statements... and maybe someday, when the proxy table feature is enhanced, you'll won't ever need SELECT * INTO #temp_table.

Other possibilities come to mind:
  • Using UNLOAD SELECT to reformat row layouts, deal with differing numbers of columns, compare subsets, etc.

  • Using a cursor FOR loop to UNLOAD individual rows for comparison.

Monday, July 27, 2009

Principles of Code Comments

Everybody has opinions about comments in program code; here's mine:

  • Don't include the file name in comments. Development tools always tell you what file you're editing, and it should be easy, not hard, to rename files when copying, reorganizing and so forth.

  • From the moment in time the code in a new file is "finished" (from the ever-optimistic developer viewpoint), start recording modification history.

  • Put the latest modification history comments at the top of the file, move old history comments to the bottom. You want to preserve history, but you don't want ancient history to get in the way.

  • Keep the modification history simple. Don't write more than one line per modification history comment unless absolutely necessary. The future reader needs to know three things only: When the change was made, who made the change (initials), and what changed, where the "when" might include the build number as well as the date. It is perfectly OK to copy and paste a snippet of code unique to the change; future readers will take it from there to find the details.

  • Put a "date started at" comment at the very top, and keep it there. Knowing when a file was originally created is very often interesting to the reader.

  • Don't decorate comments. No big boxes, no government fill-in-the-forms.

  • Do decorate warnings. It's even OK to shout, as in /* ----- WHEN MAKING CHANGES HERE ALWAYS CHECK FILE XYX.SQL ----- */

  • Do include separator and title lines if the code's long and tedious... this assumes you agree one long flat module is easier to maintain than breaking it up into separate files simply to keep the line count down. However, if you would always rather maintain 100 ten-line files plus 100 calls, than a single thousand-line file, carry on!

  • Don't clutter the code with embedded modification history comments, unless absolutely necessary. The "absolutely necessary" part might apply if, say, you are dealing with life-critical code, or for some other reason you need to communicate the exact details of the changes.

  • Don't write comments that rot. Comments are not compiled, they don't have to be correct. Don't increase the reader's level of mistrust with details unlikely to survive the first maintenance cycle.

  • Don't assume the reader is a n00b. If the reader *is* a n00b, it's up to them to learn the programming language, not you to teach them.

  • Don't assume the reader knows all about the framework. Frameworks are not languages. Languages help, frameworks hide.

  • Do include pointers to the docs. Not to the language Help, but to solution references and tutorials; e.g., where the original code came from, where relavent standards are found, and so on... if those are important to the code itself. URLs are great, Google search strings as well... the latter may survive link rot.
Here are some excerpts from a module that's at the very heart of the Foxhound Database Monitor; rroad_monitor_sample is called every 10 seconds for each target database to gather and save measurements about the server, database and client connections:

-- 2007 02 04 BC 1988a: Date begun.
-- (see bottom of file for earlier modification history)
-- 2009 07 16 BC 3440a: Changed: SET this_rroad_group_2_property_pivot.previous_ApproximateCPUTime = previous_rroad_group_2_property_pivot.ApproximateCPUTime,
-- 2009 07 16 BC 3440a: Added: Column temp_engine_properties.CurrentCacheSize DEC(20),
-- 2009 07 16 BC 3440a: Added: Column temp_engine_properties.MaxCacheSize DEC(20),
-- 2009 07 21 BC 3458a: Changed: ' Procedure rroad_ ... _properties not used; build number ', @procedure_build_number,
-- 2009 07 21 BC 3458a: Changed: -- Also note: The ISNUMERIC call is used for the same reason: The proxy queries return duplicate garbled rows.
-- 2009 07 21 BC 3458a: Removed: Old commented-out code.
-- 2009 07 21 BC 3459a: Changed: SET @sample_elapsed_msec = rroad_f_datediff_msec ( @sample_started_at, @sample_finished_at );
-- 2009 07 21 BC 3459a: Changed: SET @canarian_query_elapsed_msec = rroad_f_datediff_msec ( @canarian_query_started_at, @canarian_query_finished_at );

PARAMETERS MONITOR_DEBUG_MESSAGES;

-------------------------------------------------------------------------------------------------------------------------------------------------
MESSAGE STRING ( '****************************** CREATE PROCEDURE rroad_monitor_sample' ) TO CLIENT;

BEGIN
DROP PROCEDURE rroad_monitor_sample;
EXCEPTION WHEN OTHERS THEN
END;

-----------------------------------------------------------------------------------
CREATE PROCEDURE rroad_monitor_sample (
IN @sampling_id UNSIGNED INTEGER )

BEGIN

...

------------------------------------------------------------
-- Try the heartbeat query.

IF @ok = 'Y'
AND COALESCE ( @proxy_owner, '' ) <> '' THEN

BEGIN -- handle connection problem

SET @diagnostic_location = '204.a7';

------------------------------------------------------------
-- Record the sample start time immediately before the first proxy call.

SET @sample_started_at = CURRENT TIMESTAMP;
SET @sample_finished_at = @sample_started_at;

------------------------------------------------------------
-- Perform the basic heartbeat or canarian query.
-- This is done to calculate the heartbeat time as well check the connection.
-- Note: The target database can be stopped and restarted, and the monitor should just keep trying to connect.
-- Note: When Foxhound itself is is stopped and restarted, reconnection to target databases *should* be automatic.

SET @sql = STRING ( 'SELECT dummy_col INTO @dummy_col FROM ', @proxy_owner, '.proxy_DUMMY' );

SET @canarian_query_started_at = CURRENT TIMESTAMP;
SET @canarian_query_finished_at = @canarian_query_started_at;

EXECUTE IMMEDIATE @sql;

ROLLBACK; -- release locks, recover from possible failed proxy connection

...

END; -- rroad_monitor_sample

-- 2007 02 04 BC 1988a: Added: Column rroad_conn_property_name.sample _interval UNSIGNED INTEGER NOT NULL, -- 10 ultra, 10 fast, 60 slow
-- 2007 02 04 BC 1988a: Added: Column rroad_db_property_name.sample _interval UNSIGNED INTEGER NOT NULL, -- 2 ultra, 10 fast, 60 slow
-- 2007 02 04 BC 1988a: Added: Column rroad_eng_property_name.sample _interval UNSIGNED INTEGER NOT NULL, -- 2 ultra, 10 fast, 60 slow
-- 2007 02 04 BC 1988a: Added: Column rroad_sample_set.sample _interval UNSIGNED INTEGER NOT NULL DEFAULT 0,

...

-- 2009 07 11 BC 3430a: Added: Column temp_database_properties.MirrorMode LONG VARCHAR,
-- 2009 07 11 BC 3430a: Added: Column temp_database_properties.MirrorState LONG VARCHAR,
-- 2009 07 11 BC 3430a: Added: Column temp_database_properties.PartnerState LONG VARCHAR,
-- 2009 07 13 BC 3432a: Added: Column temp_database_properties.ReadOnly LONG VARCHAR,

Friday, July 24, 2009

The Stack Overflow Knowledge Exchange Platform

Here's all you really need to know about StackExchange:

"With StackExchange, you can run a site with all the same features that made Stack Overflow successful."
StackExchange is coming September 1. Pricing starts with a 45 day free trial, then $129 per month for 1,000,000 page views per month on a shared server, more $$ for more page views, and even more $$$$ if you want to host the server yourself... but the prices aren't stupidly high, not like, say, Oracle.

The StackExchange Beta is coming soon, you can sign up here... I have, maybe I'll set up a SQL Anywhere Overflow site!

Wednesday, July 22, 2009

Displaying Alerts

My previous post mentioned that the Foxhound Database Monitor displayed alerts and all clear messages "in multiple locations and formats, both separate from and together with other measurements in the main monitor display."

When I wrote that, it wasn't true... yet... but now it is.

Here's the Monitor tab of the Foxhound main menu, showing all the databases being monitored including their recent alert history. In this case, the ddd11 database has never had an alert issued, while the test10_local_on_tsunami database has had 17 different alert conditions at one time or another, out of a possible total of 28, and 14 are still in effect:



That takes care of the "separate" display of alerts and all clear messages mentioned above.

To see alerts in the context of other measurements, you can scroll the Monitor History page to find them... or just click on one of the links on the Monitor menu tab, in this case the 1m 58.5s ago: link on the ALL CLEAR for Alert #3.

That causes the following History page to open, scrolled to the very moment the ALL CLEAR was issued:



In this case there is some "on/off" oscillation of Alert #3, caused by the extremely aggressive alert criteria used (1 second for 1 sample). Aggressive criteria are fine for testing the alerts process itself, but aren't much use in real life.

But that's not the point here... the point is that takes care of the promise to display alerts "together with other measurements".

Monday, July 20, 2009

Comparing Database Monitors

When the next Beta of Foxhound is released (soon, soon), the SQL Anywhere Monitor will have some competition in the area of email alerts.

Here's how the two products compare as far as features are concerned:



Basic Features


SQL Anywhere MonitorFoxhound Database Monitor
Can monitor both SQL Anywhere and MobiLink servers.
Limited to monitoring SQL Anywhere target databases.
Limited to SQL Anywhere Version 11 target servers running Version 10 or 11 databases.
Can monitor Version 5, 6, 7, 8, 9, 10 and 11 databases and servers.
Multiple adjustable sampling intervals are supported, with a 10 second minimum. The defaults are 30 seconds, 5 minutes and 30 minutes for High, Medium and Low.
There's only one sampling interval, and it's fixed at 10 seconds.
Stores sample data in a dedicated Version 11 database.
Stores sample data in a dedicated Version 11 database.
Uses SQL Anywhere's built in HTTP server (port 4950) with an Adobe Flash browser interface.
Uses SQL Anywhere's built in HTTP server (port 80) with a standard HTML and JavaScript browser interface; e.g., select and copy to clipboard is supported.
Measurements shown via graphs that scroll to the right.
Measurements shown via text that scrolls up.
Separate tabs and graphs for separate measurements.
One combined display for all measurements.
- not supported -
Peak measurements are recorded, and measurements approaching the peaks are color highlighted.
- not supported -
Detailed measurements for each connection are displayed.
Basic information about each blocked connection is displayed: the connection numbers for the blocked and blocking connections.
Additional information about each blocked connection is displayed, including the SQL text for the blocked statement and for a SELECT statement you can run to find the locked row.
The GUI refresh interval defaults to 1 minute and cannot be set any faster than 30 seconds.
The GUI refresh interval is fixed at 10 seconds.
The GUI requires a login in addition to the user ids and passwords required to monitor to the target databases.
The Foxhound GUI itself requires no login... just the user ids and passwords for the target databases.
Detailed connection parameters (user id, password, host, server, database and/or port) must be provided for each target database.
ODBC DSNs may be chosen from the list of existing User and System DSNs. DSN-less connection strings may also be used.
Maintenance will be performed daily at [00] : [00]
The maintenance schedule is internally determined.
Scheduled backup via "Back up the SQL Anywhere Monitor data to the following directory: [ ]"
Backup is manual via desktop shortcut.
Yes/No: Take a daily average values older than [2 weeks] (or 1 week, 1 month, 6 months, 1 year)
- not supported -
Yes/No: Delete values older than [1 month] (or 1 week, 2 weeks, 6 months, 1 year)
Purge sample data: after 1 day, 1 week, 1 month, 1 year, never purge.
Yes/No: Delete old values when the total disk space becomes greater than (MB): [10240]
- not supported -
Yes/No: Allow anyone read-only access to the SQL Anywhere Monitor.
- not supported -



Alert Processing


SQL Anywhere MonitorFoxhound Database Monitor
Alerts are point-in-time events.
Alerts are conditions that go into and out of effect.
Detection of individual alert conditions can be enabled and disabled.
Detection of individual alert conditions can be enabled and disabled.
- not supported -
"All clear" messages are displayed and emails are sent when alerts are no longer in effect. Cancellation messages are also displayed when criteria change while alerts are in effect.
Alerts which are no longer in effect must be cleared manually via the "Mark Resolved" or "Delete" buttons.
Alerts are automatically cleared when the "all clear" and "cancelled" conditions are met.
Most alerts are issued as soon as the criteria are met.
A waiting period is part of the criteria for most alerts, with 10 samples being the most common default. The waiting period directly affects how long a condition must exist before an alert is issued, and indirectly affects how long the condition must remain resolved before an all clear is issued.
Alert messages are displayed on a separate tab.
Alerts and all clear messages are displayed in multiple locations and formats, both separate from and together with other measurements in the main monitor display.
Alerts will be repeatedly sent for a condition that persists, although the frequency can be controlled: Alerts for the same condition that occur with 5 minutes (the default) are suppressed. Other intervals may be chosen: 1 minute, 1 hour, 2 hours, 6 hours, 24 hours.
Alert messages are displayed and emails are sent ONLY when the alert goes into effect.
Can send alert emails via SMTP and MAPI.
SMTP only.
Sensible "factory setting" defaults are provided for all alert criteria.
Sensible "factory setting" defaults are provided for all alert criteria.
Changes to alert criteria must be made manually for each database.
Manually-entered alert criteria may be copied from one database to another via "Save Settings as Default" and "Restore Default Settings"
- not supported -
The original Foxhound alert criteria may be restored via "Restore Factory Settings".
- not supported -
The "Use Extreme Settings" button may be used to force the detection of more alerts, sooner, for testing purposes.
Yes/No: Suppress unsubmitted error report alerts from resources.
- not supported -



Alert Conditions


SQL Anywhere MonitorFoxhound Database Monitor
(a) Availability Alert - Database Down
Alert #1. Foxhound has been unable to gather samples for [1m] or longer.
- not supported -
Alert #2. The heartbeat time has been [1.0s] or longer for [10] or more recent samples.
- not supported -
Alert #3. The sample time has been [10.0s] or longer for [10] or more recent samples.
(b) Alert when CPU use reaches [90] % for two collection intervals in a row.
Alert #4. The CPU time has been [90]% or more for [10] or more recent samples.
(c) Alert when memory usage reaches [85] % of the maximum cache size.
Alert #19. The cache has reached [100] % of its maximum size for [10] or more recent samples.
- not supported -
Alert #20. The cache satisfaction (hits/reads) has fallen to [50] % or lower for [10] or more recent samples.
(d) Alert when free disk space per dbspace is less than [1024] MB on the disk.
Alert #5. The free disk space on the drive holding the main database file has fallen below [1GB].
Alert #6. The free disk space on the drive holding the temporary file has fallen below [1GB].
Alert #7. The free disk space on the drive holding the transaction log file has fallen below [1GB].
Alert #8. The free disk space on one or more drives holding other database files has fallen below [1GB].
- not supported -
Alert #13. There are [1000] or more fragments in the main database file.
(e) Alert when a connection has been blocked for longer than [10] seconds.
Alert #23. The number of blocked connections has reached [10] or more during [10] or more recent samples.
- not supported -
Alert #24. At least one single connection has blocked [5] or more other connections during [10] or more recent samples.
- not supported -
Alert #25. The number of locks has reached [1,000,000] or more during [10] or more recent samples.
(f) Alert when the number of connections in use reaches [85] % of the license limit.
Alert #26. The number of connections has reached [1000] or more for [10] or more recent samples.
(g) Alert when a query has run for longer than [10] seconds.
- not supported -
- not supported -
Alert #27. The approximate CPU time has reached [25] % of elapsed time or more for at least one connection during [10] or more recent samples.
- not supported -
Alert #28. The transaction running time has reached [1m] or more for at least one connection during [10] or more recent samples.
- not supported -
Alert #21. The total temporary file space used by all connections has been [1G] or larger for [10] or more recent samples.
- not supported -
Alert #22. At least one single connection has used [500M] or more of temporary file space during [10] or more recent samples.
(h) Alert when a connection attempt fails.
- not supported -
(i) Alert when the arbiter or partner server is disconnected.
Alert #9. The high availability target database has become disconnected from the arbiter server.
Alert #10. The high availability target database has become disconnected from the partner database.
- not supported -
Alert #11. The high availability target database server has switched over to [server2].
- not supported -
Alert #12. The high availability target database has changed from [read only] to [updatable].
(j) Alert when the number of unscheduled requests reaches [5]
Alert #14. The number of requests waiting to be processed has reached [5] or more for [10] or more recent samples.
- not supported -
Alert #15. The current number of incomplete file I/O operations has reached [10] or more for [10] or more recent samples.
- not supported -
Alert #16. There have been [1000] or more disk and log I/O operations per second for [10] or more recent samples.
- not supported -
Alert #17. The Checkpoint Urgency has been [100] % or more for [10] or more recent samples.
- not supported -
Alert #18. The Recovery Urgency has been [1000] % or more for [10] or more recent samples.

Friday, July 17, 2009

Wall-E, meet RIVA



RIVA the robot may not match Wall-E's sparkling personality, or even IvanAnywhere's, but you can't fault her mission: To reduce medication errors at the Children's Hospital of Orange County in Southern California.

Plus, like IvanAnywhere, RIVA runs on SQL Anywhere:

"To make the code lean, RIVA relies heavily on scripts stored inside a Sybase Inc. embedded database, SQL Anywhere."
- Thom Doherty, CTO at Intelligent Hospital Systems
Read more about RIVA here, and watch the video here.

Wednesday, July 15, 2009

Danger! NULLs!

It's legal to avoid taxes, but not to evade them. With NULLs, I don't care, I will avoid them, evade them, whatever it takes.

Like Al Gore does with global warming, whenever something bad happens I blame the NULLs.

And here's why: The code I posted in SELECT FROM Excel Spreadsheets was wrong! Because of NULLs!

Well, because of a stupid mistake *I* made involving NULLs. And it isn't really the NULLs' fault. Not really.

Here's the query that was wrong; can you see why?

SELECT proxy_browsers.browser          AS brand_name,
SUM ( proxy_browsers.hits ) AS hit_count,
hit_count / total_hits * 100.0 AS percent
FROM proxy_browsers
CROSS JOIN ( SELECT SUM ( hits ) AS total_hits
FROM proxy_browsers )
AS summary
WHERE browser IS NOT NULL
GROUP BY proxy_browsers.browser,
summary.total_hits
ORDER BY hit_count DESC;

And this is the most embarrassing part: I knew there was someting wrong, because that query gave a different answer from this one which used an OLAP WINDOW instead of a CROSS JOIN:
SELECT DISTINCT 
FIRST_VALUE ( browser ) OVER ( brand_window ) AS brand_name,
SUM ( hits ) OVER ( brand_window ) AS hit_count,
CAST ( hit_count
/ SUM ( hits ) OVER ( everything )
* 100.0 AS DECIMAL ( 11, 4 ) ) AS percent
FROM proxy_browsers
WHERE browser IS NOT NULL
WINDOW brand_window AS ( PARTITION BY browser ),
everything AS ()
ORDER BY hit_count DESC;

But I thought it was the OLAP query giving the wrong answer, not the CROSS JOIN! I didn't post the OLAP query because I thought there was a bug in SQL Anywhere 11!

Arrgh!

What's the answer? Last chance, the contest is closed...

Scroll down to see the answer...

down...

down...

down...

down...

down...

down...

down...

down...

down...

down...

down...

down...

down...

There are two SELECTs in the CROSS JOIN query but only one of them has the necessary WHERE browser IS NOT NULL. Here's the corrected CROSS JOIN query, which now returns the same result set as the (always correct) OLAP version:
SELECT proxy_browsers.browser          AS brand_name,
SUM ( proxy_browsers.hits ) AS hit_count,
hit_count / total_hits * 100.0 AS percent
FROM proxy_browsers
CROSS JOIN ( SELECT SUM ( hits ) AS total_hits
FROM proxy_browsers
WHERE browser IS NOT NULL )
AS summary
WHERE browser IS NOT NULL
GROUP BY proxy_browsers.browser,
summary.total_hits
ORDER BY hit_count DESC;

Jonathan's the clear winner in the Find The Mistake Contest; not only did he provide right answer, but he proposed an alternative solution:

Clearly you're anticipating the possibility that the "browser" column may be null, based on the "browser is not null" clause in the outer query. But your inner query that generates the total hits doesn't include this clause, which means that you're measuring percentages against the total number of hits, not the total of hits from non-null browsers.

This may or may not be considered a bug, depending on what you're trying to present. But if you have hits from null browsers, then your percentages will not sum to 100, and at a minimum this will look odd.

Fix is obviously to add "where browser is not null" to the subquery. A perhaps better fix would be to handle the null values, something like this:
SELECT coalesce(proxy_browsers.browser, 'Unknown') AS brand_name,
SUM ( proxy_browsers.hits ) AS hit_count,
hit_count / total_hits * 100.0 AS percent
FROM proxy_browsers
CROSS JOIN ( SELECT SUM ( hits ) AS total_hits
FROM proxy_browsers )
AS summary
GROUP BY brand_name,
summary.total_hits
ORDER BY hit_count DESC;

Monday, July 13, 2009

Techwave Agenda

This year's Techwave Symposium in Washington DC may be a shadow of former Techwaves, but it's not all bad.

First, there's the price, $200 for a day and a half of technical content, and then there's the content itself: The agenda for the SQL Anywhere and MobiLink sessions has just been published and it looks solid.

Oh, and registration is now open.