简体   繁体   English

是否可以从Sybase函数返回数字列表?

[英]Is it possible to return a list of numbers from a Sybase function?

I'm trying to overcome a very serious performance issue in which Sybase refuses to use the primary key index on a large table because one of the required fields is specified indirectly through another table - or, in other words; 我正在尝试解决一个非常严重的性能问题,在该问题中Sybase拒绝在大型表上使用主键索引,因为其中一个必填字段是通过另一个表间接指定的-换句话说

SELECT ... FROM BIGTABLE WHERE KFIELD = 123

runs in ms but 以毫秒为单位运行,但

SELECT ... FROM BIGTABLE, LTLTBL WHERE KFIELD = LTLTBL.LOOKUP 
   AND LTLTBL.UNIQUEID = 'STRINGREPOF123'

takes 30 - 40 seconds. 需要30-40秒。

I've managed to work around this first problem by using a function that basically lets me do this; 我已经通过使用基本上可以让我做到这一点的函数设法解决了第一个问题;

SELECT ... FROM BIGTABLE WHERE KFIELD = MYFUNC('STRINGREPOF123')

which also runs in ms. 它也以毫秒为单位运行。

The problem, however, is that this approach only works when there is a single value returned by MYFUNCT but I have some cases where it may return 2 or 3 values. 但是,问题在于,这种方法仅在MYFUNCT返回单个值时MYFUNCT但是在某些情况下,它可能返回2或3个值。

I know that the SQL 我知道SQL

SELECT ... FROM BIGTABLE WHERE KFIELD IN (123,456,789)

also returns in milliseconds so I'd like to have a function that returns a list of possible values rather than just a single one - is this possible? 也会以毫秒为单位返回,因此我希望有一个函数可以返回可能值的列表,而不仅仅是一个值-这可能吗?

Sadly the application is running on Sybase ASA 9. Yes I know it is old and is scheduled to be refreshed but there's nothing I can do about it now so I need logic that will work with this version of the DB. 可悲的是,该应用程序在Sybase ASA 9上运行。是的,我知道它很旧,并且计划进行刷新,但是现在我无能为力,所以我需要可以在此版本的DB上使用的逻辑。

What about using a temporary table to store your numbers? 使用临时表存储电话号码怎么办? So your sql would look like this: 所以你的sql看起来像这样:

    select kfield into #tmpKfield 
    from littleTable 
    where UNIQUEID = 'STRINGREPOF123'

    select * from bigTable 
    where kfield in (select kfield from #tmpKfield)
    go

    drop table #tmpKfield
    go

That is how I try to solve your issue. 这就是我试图解决您的问题的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM