RecordSortedList 和临时 table

RecordSortedList and temporary table

我有多个临时 table 的性能问题,我试图用 RecordSortedList 解决,但我得到了奇怪的结果。我有一个临时 table,其中插入了数十万条记录,然后在别处用于连接到其他临时 table。问题是在跟踪解析此解决方案之后,插入对于所有单独的插入花费的时间太长,我希望使用 RecordSortedList 批量插入到暂存 table。但是,在 RecordSortedList.insertDatabase() 调用后,我找不到临时 table 的句柄。

我试过这样的事情:

RecordSortedList tmpTableSortedList;
MyTempTable myTempTable;
AssetTrans assetTrans;
int i = 1;

tmpTableSortedList = new RecordSortedList(tableNum(MyTempTable));
tmpTableSortedList.sortOrder(fieldNum(MyTempTable, LineNum));

//the real scenario has a much more complicated data gathering, but just for sample
while select * from AssetTrans 
{
    myTempTable.AssetGroup = assetTrans.AssetGroup
    myTempTable.LineNum = i;

    tmpTableSortedList.ins(myTempTable);

    i++;

}

tmpTableSortedList.insertDatabase();

//strange things happen here
MyTempTable myTempTableCopy;
AnotherTmpTable anotherTmpTable;

tmpTableSortedList.first(myTempTableCopy); //returns a buffer, but not usable buffer in join.

//does not work, I imagine because the myTempTableCopy isn't actually pointing to the 
//inserted records above; somehow the temp table is out of scope.
while select * from anotherTmpTable
join myTempTableCopy
where anotherTmpTable.id == myTempTableCopy.id
{
    //logic
}

有没有办法在调用 RecordSortedList.insertDatabase() 后获取指向临时 table 的指针?我也试过 linkPhysicalTable() 和其他一些东西,但也许 RecordSortedList 不应该与 tempDb tables?

一起使用

编辑:就像 Aliaksandr 在下面指出的那样,这适用于 RecordInsertList 而不是 RecordSortedList

but maybe RecordSortedList was not supposed to be used with tempDb tables?

使用 TempDb 时的错误消息 tables:

RecordInsertList or RecordSortedList operations are not allowed with database temporary tables.

所以这是不允许的,这可能是有道理的,因为 RecordSortedList 是一个 memory-based 对象而 TempDb table 不是。我认为你可以,因为我不确定 TempDb table 和 Regular table 当它们都存储在磁盘上时是否存在巨大差异?

如果您想使用 InMemory table,请查看 \Classes\CustVendSettle 特别是变量 rslTmpOverUnderReverseTax,它使用 InMemory table.

IF TempDb table 是允许的,您将使用 getPhysicalTableName() 来获取与 useExistingTempDBTable() 组合的句柄。

还是我误读了你的问题?

does not work, I imagine because the myTempTableCopy isn't actually pointing to the inserted records above; somehow the temp table is out of scope.

RecordSortedList 的方法 new 有额外的 Common 参数,您应该在其中传递您的 tempDB table 缓冲区。

Error message when using TempDb tables:

RecordInsertList or RecordSortedList operations are not allowed with database temporary tables.

So it's not allowed, which might make sense because RecordSortedList is a memory-based object and TempDb tables are not.

虽然消息说我们不能使用临时 tables 进行此类操作,但我们确实可以。我们只是需要小心,因为代码必须在服务器上执行。

RecordSortedList objects must be server-located before the insertDatabase method can be called. Otherwise, an exception is thrown.

I have a temporary table that has a couple hundred thousand records being inserted into it

RecordSortedList对象的大小没有限制,但是完全memory-based,所以存在潜在的内存消耗问题。所以这可能不是您的最佳解决方案。