Question

If we create an index like this:

create nonclustered index idx_person on person(gender, name)

in ASE 12.5, there'll be created statistics (more precisely an histogram) for the major atribute (gender) but nothing is done for the minor atribute name.

Because of that, the optimizer can select a worst query plan when making a select like this:

select * from person
where gender = 'M'
and name = 'John Doe'

It might choose a worst query plan because it'll give the default selectivity values for the column name. With that, a table scan can be better than choosing the index.

!

What I want to know is if in ASE 15.x, when a index is created with more than one column, the statistics are run for all index columns?

Or if we've to use the following commands to update the index statistics:

update statistics person(name)

update index statistics person index_person

Thanks in advance! :)

Was it helpful?

Solution

You don't get the stats on 2nd and subsequent columns by default, I suppose because Sybase has to do more processing and use the tempdb to compile them. Therefore you're expected to decide which of your indexes need all their columns with stats.

If you're on v15 and you have optimisation level set to "mix" or "dss" you're likely to have a problem where you don't keep stats on all index columns, because the optimiser can't easily get merge and hash joins right without all index column stats. On v12.5 the same applies if you have MERGE JOIN turned on.

I'd think it might be likely you'd have more problems of that kind than wrong plans just because of no histogram on 2nd and subsequent columns, though I guess it depends.

You can use the DATACHANGE function to find out which tables have changed by more than some percentage you give, so that you could write a shell script (or whatever) that periodically (once an hour/several hours/day/start of batch/end of batch/etc) checks the database and updates stats for affected tables. (Actually I'm not quite sure that's on 12.5 - it might well be v15 only.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top