To really know what is happening is to see how Sybase is planning the query. I.e. how it fetches the data. It sounds like it’s not using the index at all when it gets a distinct.
If my google-skills don’t deceive me you need to use the following command to show the query plan:
set showplan on;
And then run your query.
Paste the result back on the forum so we can look into it.
To be clear you do all this in isql.
Also have you tried a GROUP BY instead of a DISTINCT. I have had situations when a GROUP BY was faster than a DISTINCT.
select distinct’s plan is this:
( Plan [ Total Cost Estimate: 51139.95502 ]
( OrderedDistinct
( IndexScan Data network_code )
but, select using group by is this:
( Plan [ Total Cost Estimate: 219.148704 ]
( WorkTable
( HashGroupBy
( TableScan Data )
both are slow
I did find a post on dbforums that claims in order to use an index, you can not allow nulls. So, I turned “allow null” off, but no difference. Sybase online books offers this “Many statements take significantly longer to execute when DISTINCT is specified”
Quite amazing that scanning an index takes this long. Have you tried to reindex the column?
Also another option would be to move the data out of that table and relate it back from a seperate table. This way you have a table with 91 values that are loaded up in no time.
gdurniak:
as a quick fix, I did export the data into a separate table for the valuelist
but, is this SQL workaround required, or expected? has anyone successfully created a valuelist from a “large” table?
Well data-modeling wise it’s proper to put in a separate table and relate it (by ID). So the the answer to that would be Yes.
gdurniak:
also, surprising that Servoy generates the valuelist when the form opens, so it locks up, rather than on combobox entry
It does that because it also uses the valuelist for displaying the value. This is of course a requirement when you have a real and display value in your valuelist.
I did manage to confirm this on the sybase.public.sqlanywhere.general newsgroup. Select distinct or “group by” on 5 million records will be somewhat slow, so generating a valuelist directly is out of the question.
Sybase claims that SQL Anywhere 11.0 may have this feature
In the mean time, I will be forced to maintain & update a separate “valuelist” table. The is data sent to us, so we have no control
gdurniak:
I don’t see it in the Servoy App Server Performance statistics …
They do show up for me though.
What version of Servoy are you using ? And also how do you load your valuelists?
By way of a method (application.setValueListItems()) or by letting Servoy fetch the data?