Subject: Sybase FAQ: 14/16 - section 10.4
Date: 1 Sep 1997 06:12:19 GMT
Summary: Info about SQL Server, bcp, isql and other goodies
Posting-Frequency: monthly

Archive-name: databases/sybase-faq/part14
URL: http://reality.sgi.com/pablo/Sybase_FAQ

                                   Q10.4.1

                            Sybase Technical News

                             Volume 6, Number 1
                                April 1, 1997

----------------------------------------------------------------------------
In this issue

Message from the Publishers
Tip of the Month: Swap Space
TechNote Summaries
Other Useful Information
Subscription Information
Feedback

Message from the Publishers

Sybase Technical News is back! You asked for an email version of TechNews
delivered monthly. We heard you, and we took action. Each month we'll send
you technical information, tips, and suggestions about where you can learn
more about solutions with Sybase, Inc. products.

The survey:

In January, Sybase Support Publications surveyed the Sybase Technical News
email subscribers to determine the future direction of Technical News. A
healthy number of you responded--20% of the 1,200 people on our email list.
Here's what you told us, and the changes we have planned in response. Thank
you to all of our readers who participated!

What you said:

   * Most of you still want to hear from us via email, although many would
     prefer simple notification of new issues with a list of the articles
     they include.
   * While many of you liked the idea of being able to select articles based
     on your areas of interest, a significant number of you also said you
     rely on us to select the most relevant articles for you.
   * Some of you still want to receive the full-text of each issue via email
     because you don't have World Wide Web access, aren't a named Support
     contact, don't have a secure browser, or because it's just more
     convenient to get your news in email and therefore you are more likely
     to read it.
   * Well over half of you said you'd prefer to receive a new TechNews
     monthly, rather than quarterly.
   * 80% of you said that the information you find in Tech News
     occasionally, saved you a call to Tech Support. 34% of you said it had
     occasionally caused you to call us with more questions. (We'll keep
     striving to provide more complete information so you won't need
     follow-up.)

What we're doing:

   * Publishing monthly instead of quarterly and working closely with the
     folks on the phones to make sure you get the most timely information
     available.
   * Making Sybase Technical News a publicly available newsletter once
     again. Most of the Online Support Services Technical Information
     Library will be moving onto the Sybase public web pages later in Q2. In
     the meantime, the Sybase Technical News email subscription list will
     allow you to subscribe regardless of your support license status, and
     we will again allow posting of Sybase Technical News to public forums
     such as comp.databases.sybase.
   * Moving subscription management to a true list server instead of
     manually. This means we can maintain two lists:
        o inews-technews-summary for those of you who just want the
          notification and article summaries
        o inews-technews-full for those of you who prefer the entire ascii
          version.
   * Including more information in Technical News on how to access other
     Sybase electronic information sources.

Changes in personnel:

Leigh Ann Hussey, after serving several years as editor-in-chief, now
becomes engineer-in-chief, helping us integrate Technical News production
with our new online electronic publishing environment. Betsy Brazy will take
on the editor-in-chief position, backed by a strong staff of technical
writers and information managers, and a dedicated pool of Technical Support
engineers.

As always, we look forward to hearing from you; send comments to
technews@sybase.com. Subscription requests should no longer be sent to this
alias; instead, direct them to majordomo@sybase.com . Complete subscription
instructions appear in the Subscription Information section later in this
newsletter.

Tip of the Month: Swap Space

The idea of swap space is simpler than most of us believe. Swap space is
actually space on the hard disk. It is not somewhere in volatile memory, nor
does it affect physical memory. It is disk space and it is cheap. What
happens in a swap is that data that is in volatile memory - usually RAM - is
taken as a lump and saved to disk. Maybe you "swap out" 16MB to the disk, a
small amount to the average 4 gigabyte disk. You can swap out many times
before filling the disk.

Because of OS functions, the system "thinks" it has 4 times 32MB, 75% of
which is slower. Should you add disk space or should you add RAM? Think SWAP
for capacity, RAM for speed.

TechNote Summaries

----------------------------------------------------------------------------

                 Simulating Row-Level Locking in SQL Server

----------------------------------------------------------------------------

Summary

You can simulate row-level locking for highly concurrent, small tables by
placing one record on a page with filler fields or with SQL Server 11's
max_rows_per_page parameter. This workaround involves trade-offs that may
not be suitable for your configuration.

Attributes
 OS: All             Version: All
 Platform: All       Last Revision: 14 Feb 1997
 Product: SQL Server ID: 2710

Contents

This TechNote helps to determine when this workaround would be useful for
you as well as the trade-offs of forced row locking.

How to Create Row-Level Locking

When you make the record size large enough, SQL Server allocates each row to
its own page. Thus, when accessed, SQL Server locks only one record at a
time, effectively simulating row- level locking. None of these options, of
course, constitute true row-level locking.

SQL Server 10.x and earlier

Use filler fields (for SQL Server 4.9.2 and 10.x) to make the record size
just over half a page.

SQL Server 11.x

You can adjust the number of rows on a table or index. SQL Server retains
the max_rows_per_page value when adding or deleting rows. Decrease the
max_rows_per_page value when using create table, create index, or alter
table. For example,

        alter table sales

        with max_rows_per_page = 1

For existing data, use the system procedure sp_chgattribute for tables or
indexes. For example:

        sp_chgattribute authors, "max_rows_per_page", 1

You can use the system procedure sp_helpindex to view the value of
max_rows_per_page.

Should You Use This Workaround?

Most applications, if tuned properly, do not benefit from forced row
locking. Cases which would are those with small tables where many rows in
the table are used or modified heavily.

For example, you may want to use this procedure for a table that holds
unique counter numbers such as invoice_number, order_number, and so on.
Counter records are usually so small that when one application needs the
next number for some value such as invoice_number, no other processing of
other types of counters, such as order_number, can continue.

Complete this checklist to determine whether this workaround is for you.

Step 1: Examine Your Table Needs

You might use this procedure if

   * You don't want the application to be locked due to page contention
   * You experience lock contention
   * You have more than one row per page now
   * You can afford an increase in disk space

Step 2: Test the Impact of Implementing This Workaround

Run the optimizer, examine your logs and answer the following questions:

   * Is disk space at a premium? If yes, consider whether you can afford to
     add disk space, or other ways to reduce disk space.

   * What is the impact to physical I/O?
   * If your application is not tuned, following tuning procedures in the
     SQL Server Performance and Tuning Guide and test again. Consider
     whether you can afford the impact to physical I/O.

   * What is the impact to logical I/O?
   * You may find that there's no impact to physical I/O, but logical I/O
     could increase significantly.
   * What is the impact to the optimizer?
   * You may have to tune the optimizer and test again. See Analyzing and
     Resolving Optimizer Problems/Symptoms.
   * Does the application have highly concurrent tables? If yes, you may
     want to consider forced row locking.

Step 3: Weigh the Benefits and Costs

After testing, consider whether the benefits of forced row locking outweigh
its costs.

      Benefits                               Costs

 reduces contention possible increase in page splits when data is inserted
                    into a table

 limits concurrency may affect the optimizer's costing of a qualifying
                    index
                    more physical I/O when scanning
                    more logical I/O because number of pages in table
                    increase (1 page per row)
                    more memory
                    more locks, which consumes memory
                    requires more disk space

     ------------------------------------------------------------------
     Note
     See "Reducing Lock Contention with max_rows_per_page" in the SQL
     Server Performance and Tuning Guide. See the SQL Server System
     Administration Guide for information on allocating resources.

----------------------------------------------------------------------------

                    Known Bugs in Special OR Processing

                        Affecting OR and IN Clauses

----------------------------------------------------------------------------

Summary

This TechNote offers an interim workaround and information about a fix for a
known problem with the processing of OR and IN clauses.

Attributes

 OS: n/a             Version: 10.0.2.5, 10.0.2.6, 10.0.2.7, 11.0.1, 11.0.2.
                     11.0.2.1
 Platform: n/a       Last Revision: 13-Jan-97
 Product: SQL Server ID: 2695

Contents

   * Background
   * The Problem
   * Determining Whether Your Application Is Affected
   * The Interim Workaround
   * The Fix

Background

In SQL Server release 10.0.2.5, Sybase introduced a new strategy for
processing OR clauses in queries, which was designed to improve performance.

Sybase employs the "special OR strategy" for queries that contain OR or IN
clauses.

     ------------------------------------------------------------------
     Note
     SQL Server treats the IN operator as an implicit OR.
     ------------------------------------------------------------------

The following table summarizes each type of clause and provides an example
of each:

 Clause                  Example
        1> select a1, a2 from A
 OR     2> where (a1 = 10 and a2 =20 and a3 = 30)
        3> or (a2 =7 and a1 = 5 and a3 = 12)
        4> go
        1> select a1, a2 from A
 IN     2> where a1 in (100, 200, 300, 400)
        3> go

The Problem

Due to a design error, SQL Server may either return inconsistent results or
stack trace when it employs the special OR strategy. SQL Server can return
inconsistent results without reporting an error.

Determining Whether Your Application Is Affected

If your application contains an OR or IN clause and you are running one of
the following SQL Server releases then your application may be affected:

   * 10.0.2.5 or later in the 10.0.2 codeline
   * 11.0.1 or later in the 11.0.1 codeline
   * 11.0.2 or later in the 11.0.2 codeline

The Interim Workaround

To work around this problem, run SQL Server with trace flag 304. Trace flag
304 turns off the special OR optimization strategy, causing SQL Server to
choose another strategy.

Modify the syntax in your RUNSERVER file to include trace flag 304, as in
this example:

                /usr/u/sybase/bin/dataserver -dmaster_device

-sserver_name -eerrorlog -iinterfaces_path -T304

The Fix

The following table summarizes the availability of fixes for bugs related to
the special OR strategy:

 Bugid  Fix available in SQL Server version  Version release date
 84698  11.0.2                               Released
 87890  11.0.2.2                             Q1 1997
 91679  11.0.2                               Released
 92911  11.0.2                               Released
 93978  11.0.2.2                             Q1 1997
 94786  11.0.2.1                             Released
 96196  10.0.2.8                             Q2 1997
 96804  11.0.3                               Q2 1997
 121489 10.0.2.8                             Q2 1997
 121836 11.0.2.2                             Q1 1997

----------------------------------------------------------------------------

                      Backup Server Dies Unexpectedly

----------------------------------------------------------------------------

Summary

Backup server dies unexpectedly, or fails to stay up on system reboot.

Attributes
 OS: UNIX               Version: 10.0.x, 11.0.x
 Platform: na           Last Revision: 30-Dec-96
 Product: Backup Server ID: 1240

Contents

Problem Description:

One or more of the following circumstances occurs:

   * The Backup Server process disappears for no apparent reason.
   * The Backup Server fails to boot on system restart although the SQL
     Server starts fine.
   * The Backup Server process disappears when the login session (parent
     process) used to start the Backup Server logs out.
   * The SQL Server sometimes does not boot at system startup.

Cause:

The Backup Server does not handle the hangup (HUP) signal gracefully.

The SQL Server does not handle the HUP signal immediately on boot. If the
boot sequence finishes before the SQL Server process can trap the HUP signal
properly, the SQL Server dies.

Resolution:

Start the Backup Server and SQL Server with the UNIX nohup command. You may
wish to change your startup script.

For example:

nohup su sybase -c "$SYBASE/install/startserver

              -f $SYBASE/install/RUN_SYB_BACKUP.orig 2>&1" >/dev/null

For more information about using the startserver utility, see SQL Server
Utility Programs for UNIX.
----------------------------------------------------------------------------

                    Using Transact-SQL to Compare Dates

----------------------------------------------------------------------------

Summary

This TechNote gives three brief examples of how to perform date calculations
and comparisons using Transact-SQL.

Attributes
 OS: n/a               Version: n/a
 Platform: n/a         Last Revision: 10-Mar-97
 Product: Transact-SQL ID: 1227

Contents

   * Example 1: Date Comparison with datepart
   * Example 2: Date Comparison with datediff
   * Example 3: Converting Times using datediff

Example 1: Date Comparison with datepart

In some cases, it is handy to perform calculations while ignoring the "time"
portion of a datetime field. This example compares the values in the column
datetime_col against the current day, month and year using the datepart
command and the getdate() function:

        select datetime_col from table t where

        datepart(dd, t.datetime_col) = datepart(dd, getdate())

        and

        datepart(mm, t.datetime_col) = datepart(mm, getdate())

        and

        datepart(yy, t.datetime_col) = datepart(yy, getdate())

You can modify this example to compare against any target date.

Example 2: Date Comparison with datediff

You can use datediff instead of datepart to accomplish the same type of
calculation as in Example 1:

        select datetime_col from t where

        (datediff(dd, getdate(), t.datetime_col) >=0) and

        (datediff(mm,getdate(), t.datetime_col) >=0) and

        (datediff(yy, getdate(), t.datetime_col) >=0)

You can also modify this example to compare against any target date.

     ------------------------------------------------------------------
     Note
     The comparison operations described in Examples 1 and 2 do not
     effect the display format of the results. Use the convert()
     function to set your date format. For more information on
     convert() and datetime formats see the SQL Server Reference
     Manual.
     ------------------------------------------------------------------

Example 3: Converting Times using datediff

Assume that you want to calculate the number of hours between the query run
time (that is, using the getdate() function), and the midnight before the
query run time. You can do this by converting the time and using datediff
against the result.

Enter this Transact-SQL script:

        1> set nocount on

        2> declare @rightnow datetime

        3> declare @midnite datetime

        4> select @rightnow = getdate()

        5> select CURRENT_DATE = @rightnow

        6> select @midnite = convert

(datetime,convert(char(12),getdate(),6))

        7> select PREVIOUS_MIDNIGHT = @midnite

        8> select NUMBER_OF_HOURS =

datediff(hour,@midnite,getdate())

        9> go

Your output will look like this:

CURRENT_DATE

 ---------------------------

        Nov  17 1996 4:48PM

PREVIOUS_MIDNIGHT

 ---------------------------

        Nov  17 1996 12:00AM

NUMBER_OF_HOURS

 ---------------

              17

For more information on dates and datetime manipulation, see the SQL Server
Reference Manual and the Transact SQL User's Guide.
----------------------------------------------------------------------------

                Upgrade of SQL Server from 11.0.1 to 11.0.2

                               on Windows NT

----------------------------------------------------------------------------

Summary

This alert describes a problem that users may encounter when upgrading from
SQL Server version 11.0.1 to 11.0.2 on the Windows NT platform. A detailed
problem discription and workaround are included.

Attributes
 OS: Windows NT      Version: 11.0.2
 Platform: PC        Last Revision: Feb 3, 1997
 Product: SQL Server ID: 2715

Contents

Problem description:

Users are encountering a problem when they upgrade from 11.01 to 11.02. It
occurs if a customer has not fully qualified the physical device name with a
complete path. System 11.02 cannot find the device (by default it is in the
winnt35system32 directory, if the SQL server is started as a NT service) and
marks the database suspect during the upgrade. During the upgrade the SQL
server uses the RUN_server batch to restart and may have a default directory
different from the default directory when the unqualified device was
created.

For example: If a user creates a device with the name of "test" and physical
file name of "test.dat" without qualifying the physical location of the
file, the file will be created in c:winnt35system32test.dat. The following
will be stored in sysdevices table:

1>  select name, phyname from sysdevices

where name = "test"

2>  go

 name  phyname
 test test.dat

If a database created on the device is testdb, during the upgrade testdb
will be marked suspect.

The following are a list of commands to issue through ISQL in order to solve
this problem:

These isql commands must be executed in master:

1>  use master

2>  go

Turn flag to allow update to system tables:

1>  sp_configure "allow updates",1

2>  go

Setup the explicit path for the device in sysdevices:

1>  update sysdevices set

phyname="c:winnt35system32test.dat"

where name="test"

2>  go

Reset the suspect bit of the database:

1>  update sysdatabases set status = status

^ 256 where name ="testdb"

2>  go

Disallow update to system table.

1>  sp_configure "allow updates",0

2>  go

Shutdown SQL Server and restart SQL Server.

----------------------------------------------------------------------------

Other Useful Information

   * SQL Server 11.x Bug Report
   * Compatibility /Availability
   * End-of-Life/End-of-Support
   * Error Messages
   * SQL Server 11 Migration Guide: Moving from 10.x or 4.x to 11.x
   * What's New

You can access this information electronically via

   * SupportPlus Online Service's Technical Information Library. Follow
     these steps:
       1. Point your browser to Sybase
       2. click on the Technical Support button.
       3. click on "Sybase Enterprise Technical Support"
       4. click on "Enter SupportPlus Online Services".

If you aren't registered for SupportPlus, register from this page. You must
have an active support license and be a Technical Support Contact. If you
are a registered Technical Support Contact, enter your User ID and Password
and click on Technical Information Library.

   * Sybase's quarterly AnswerBase CD-ROM. To request an AnswerBase CD, call
     1-800-8-SYBASE.

Subscription Information

To subscribe to either inews-technews-full or inews-technews-summary, send
email to majordomo@sybase.com , and in the body of your message put
subscribe <list> where <list> is the list of your choice. No subject line is
necessary. For example:

subscribe inews-technews-summary

To unsubscribe, send email to majordomo@sybase.com , and in the body of your
message put unsubscribe <list> where <list> is the list of your choice. No
subject line is necessary. For example:

unsubscribe inews-technews-summary

Feedback

Send comments to technews@sybase.com.

----------------------------------------------------------------------------
All contents copyright 1997 Sybase, Inc. All rights reserved.
-- 
Pablo Sanchez              | Ph # (415) 933.3812        Fax # (415) 933.2821
pablo@sgi.com              | Pg # (800) 930.5635  -or-  pablo_p@pager.sgi.com
===============================================================================
I am accountable for my actions.   http://reality.sgi.com/pablo [ /Sybase_FAQ ]
