Sybase ASE/REP Interview Questions

Sybase ASE/REP Interview Questions

Sybase ASE Indexes -2

0

 

Creation of Indexes:

You can create the index either of two ways:

  • With Create index command
  • By specifying Integrity Constraints like Primary Key and Unique Key in create table command.

Integrity constraints (Primary and Unique Keys) have following restrictions for the indexes:

  • You cannot create non unique indexes.
  • You cannot set various setting provided by create index command like ignore_dup_key,ignore_dup_row etc.
  • You cannot drop these indexes without alter table command.

When we specify the Primary Key in create table command, it creates Unique Cluster Index and unique Key creates unique non clustered index on the column mentioned in keys.

Summarize as -

  • Primary Key in create table command ==> Creates Unique Clustered Index
  • Unique Key in create table command  ==> Creates Unique non clustered Index
  • If neither the clustered nor the nonclustered keyword is used ==> ASE will create non clustered indexes.
  • If unique keyword is not used in create index command ==> ASE will create non unique indexes.

 

Create Index Command Syntax:

create [unique] [clustered | nonclustered] index index_name
on [[database.]owner.]table_name
(column_expression [asc | desc]
[, column_expression [asc | desc]]…)
[with {fillfactor = pct,
max_rows_per_page = num_rows,
reservepagegap = num_pages,
consumers = x, ignore_dup_key, sorted_data,
[ignore_dup_row | allow_dup_row],
statistics using num_steps values}]
[on segment_name]
[index_partition_clause]

Before executing create index, turn on select into: sp_dboption,’select into’, true

The simplest form of create index is: Create index index_name on table_name (column_name)

 

Viewing Indexes:

  • Using sp_helpindex we can view indexes of a table. E.g. sp_helpindex ‘tablename’
  • sp_statistics also  returns a list of indexes on a table. E.g. sp_statistics ‘tablename’
  • In addition, if you follow the table name with “1”, sp_spaceused reports the amount of space used by a table and its indexes. E.g. sp_spaceused ‘tablename’,1

Dropping indexes

  • The drop index command removes an index from the database.
  • Only the owner of an index can drop it. drop index permission cannot be transferred to other users. The drop index command cannot be used on any of the system tables in the master database or in the user database.
  •  You cannot drop indexes using drop index command which were created using Integrity constraint. To drop the same indexes you should use alter table command.

Index Option ( for Create Index Command):

 i)ignore_dup_key  :

  • This option is only for unique clustered and non clustered indexes.
  • If you try to insert a duplicate value into a column that has a unique index, the command is canceled. You can avoid this situation by including the ignore_dup_key option with a unique index. Your command would be successful and it will ignore that key value (It means, finally no insert on the table).
  • You cannot create a unique index on a column that already includes duplicate values, whether or not ignore_dup_key is set.

ii) ignore_dup_row and allow_dup_row:

  • These options are only for the non unique clustered index.
  • These options are not relevant when creating a nonclustered index. Since an Adaptive Server nonclustered index attaches a unique row identification number internally, duplicate rows are never an issue—even for identical data values.
  • A nonunique clustered index allows duplicate keys, but does not allow duplicate rows unless you specify allow_dup_row. If allow_dup_row is set, you can create a new nonunique, clustered index on a table that includes duplicate rows, and you can  insert or update duplicate rows.
  • The ignore_dup_row option eliminates duplicates from a batch of data. When you enter a duplicate row, Adaptive Server ignores that row and cancels that particular insert or update with an informational error message.
  • If a table has duplicate rows and you are creating non unique clustered index with ignore_dup_key, it will delete all the duplicate rows from the table.

iii)Sorted Data:

  • The sorted_data option of create index speeds index creation when the data in the table is already in sorted order. sorted_data speeds indexing only for clustered indexes or unique nonclustered indexes.
  • Creating a nonunique nonclustered index is, however, successful, unless there are rows with duplicate keys. If there are rows with duplicate keys, an error message appears and the command is aborted.

 

Source : http://sybooks.sybase.com                                                                                                                                  Continue…

Sybase ASE Indexes

0

Index:

Indexes are the most important physical design element in improving database performance:

Indexes help to avoid table scans. A few index pages and data pages can satisfy many queries without requiring reads on hundreds of data pages.

Indexes in ASE:

We can divide ASE indexes in two categories by : i) Physical Order of Data with index key  ii) Uniqueness of the index column

Based on the physical order of data, Adaptive Server provides two general types of indexes that can be created at the table or at the partition level:

Clustered indexes, where the data is physically stored in the order of the keys on the index:

• For all pages-locked tables, rows are stored in key order on pages, and pages are linked in key order.

• For data-only-locked tables, indexes are used to direct the storage of data on rows and pages, but strict key ordering is not maintained.

Non clustered indexes, where the storage order of data in the table is not related to index keys

Based on index column uniqueness, indexes can be unique and non unique.

So following types of indexes present in ASE with permutation and combination with above two properties:

1. Unique Clustered Indexes

2. Non unique Clustered Indexes

3. Unique Non-clustered Indexes

4. Non unique Non-clustered indexes

 

Clustered Index Non Clustered Indexes
Unique Unique Clustered Index Unique Non Clustered Index
Non – Unique Non Unique Clustered Index Non Unique Non Clustered Index

So, all the indexes come under above 4 types:

 

In case of more than one index column, we can add prefix composite in above types.

Means Composite indexes are those indexes, which are created on more than on one column. Above four types of index can be composite as well.

In the case of partitions, we can categories above types as local and global indexes.Local indexes get created at partition level and table level index called as Global indexes.

Global indexes with one index tree cover the whole table, or local indexes with multiple index trees, each of which covers one partition of the table.

Function-based indexes are a type of non clustered index which use one or more expressions as the index key.

 

Sybase IQ Installation

0

Hi All,

Please find attached Sybase IQ Installation on Unix/Linux platform.

Sybase_IQ_installation

Implementation of Function String in Sybase Replication Server(SRS)

0

These experience shared by  Senior DBAs as name mentioned, Hope this  will help you to understand more about function string from implementation point of view in a Replication environment: 
Craig Oakley , Senior DBA.
—————————--

We used function strings when we wanted to replicate all columns to some servers, and only selected columns to other (web-facing) servers. This was particularly useful before Rep Server allowed multiple RepDefs on the same table. One concern was text columns which were not being replicated to the web-facing server: we had to create a function string to get a text pointer (we used a one-row table and just update all the text columns on top of each other, as the value was not needed on that server): failure to get a text pointer cause the DSI to go down, and we could not specify that as a condition to ignore.

Beyond this, I would imagine function strings could help specify how you want the update to be done, which could be a performance improvement. It would also allow for a different implementation at the replicate than there is at the primary (such as a table at the primary being two joined tables at the replicate).

 

Sukhesh Nair, Senior Sybase DBA
———————————–

We used to have a setup where data was replicated from sybase to oracle as also to a warm standby sybase server. Rep Server function strings helped in filtering data that would need to be passed to Oracle. It helped immensely in streamlining the data flow to targets by manipulating the incoming data through function string. I feel it is one of the most advanced and useful yet very less used capabilities of Sybase Rep Server.
The deterrent could be because of the complexity it would introduce to the replication system. The setup we had worked wonderfully and never gave us any major problems. Without proper monitoring (which needs to be scripted by DBAs) it used to be hard to maintain. Many of the current Rep Server administrators I see do not have adequate knowledge or experience of handling function strings.

Rey Wang , Senior Sybase DBA
————————-

You can map the delete to no op with functional string.

Partha Gogoi Senior DBA
————————-

We use function strings to transform data at the replicate..We have databases being replicated from Toronto and New York to London, Sydney and Singapore and the client ids are transformed at the replicate because, as per business requirements, the client ids are different at each site.. Of course , having a Universal client id would simplify things , but the systems and databases at each site grew independently until replication was set up and it would be a lot of rework to change all the client ids at the replicate sites

Øystein Grinaker Senior DBA
—————————

A Function String could be used to change default behaviour.
Say you delete a row in a table on PDB, but you do not want to delete the row on the RDB. Then make a change in rs_delete. You may make the rs delete just to make a logical delete by updateing a deletemarker for that spesific row.

 

Source : Linkedin.com

http://www.linkedin.com/groups/What-are-possible-usage-Function-3955841.S.65585220?qid=4eb177c2-d7e3-4572-9be4-92d640046c6c&trk=group_most_recent_rich-0-b-ttl&goback=%2Egmr_3955841

 

 

Inserting data into a data-only-locked heap table

0

When users insert data into a data-only-locked heap table, Adaptive Server tracks page numbers where the inserts have recently occurred, and keeps the page number as a hint for future tasks that need space. Subsequent inserts to the table are directed to one of these pages. If the page is full, Adaptive Server allocates a new page and replaces the old hint with the new page number.

/***********************************************************************************************************
Blocking while many users are simultaneously inserting data is much less likely to occur during inserts to data-only-locked heap tables. When blocking occurs, Adaptive Server allocates a small number of empty pages
and directs new inserts to those pages using these newly allocated pages as hints.
**********************************************************************************************************/

For datarows-locked tables, blocking occurs only while the actual changes to the data page are being written; although row locks are held for the duration of the transaction, other rows can be inserted on the page. The row-level locks allow multiple transaction to hold locks on the page.

If conflicts occur during heap inserts
————————————–
Conflicts during inserts to heap tables are greatly reduced for data-onlylocked tables, but can still take place. If these conflicts slow inserts, some workarounds can be used, including:

• Switching to datarows locking, if the table uses datapages locking
• Using a clustered index to spread data inserts
• Partitioning the table, which provides additional hints and allows new pages to be allocated on each partition when blocking takes place

Go to Top