物化和非物化序列
“materialized”(物化)这一术语用于表示由数据库查询生成的序列。对其他序列执行操作而得到的序列通常是未物化的。某些分析操作,如追加和搜索,只能在物化序列上执行。以下各节将说明在不同的原生语言 API 中如何使用物化序列和未物化序列。
C API
在以下代码片段中,序列迭代器 close_iterator 管理一个已实例化的序列,因为它是从“结果集”游标 quote_cursor 的一行中提取出来的;而 max_iterator 则是网格聚合 max 操作的非实例化结果序列:
mco_trans_h trans;
mco_cursor_t quote_cursor;
Quote quote;
mco_seq_iterator_t close_iterator, max_iterator;
MCO_RET rc;
mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &trans);
Quote_by_sym_index_cursor(trans, "e_cursor);
for (rc = mco_cursor_first(trans, "e_cursor);
rc != MCO_S_CURSOR_END;
rc = mco_cursor_next(trans, "e_cursor))
{
/* Get current object */
Quote_from_cursor(trans, "e_cursor, "e);
/* Materialize the close iterator */
Quote_close_iterator("e, &close_iterator);
/* Produce the non-materialized max sequence */
rc = mco_seq_grid_agg_max_float(&max_iterator, &close_iterator, 7);
...
}
rc = mco_trans_commit(trans);
Python
在以下代码片段中,序列迭代器 quote.close 管理的是一个已实例化的序列,因为它是从“结果集”Quote 游标的一行中提取出来的;而 maxit 则是 grid 聚合 max 操作的非实例化结果序列:
con.startTransaction(exdb.Transaction.MCO_READ_ONLY)
cursor = con.cursor("Quote", "by_sym")
for quote in cursor:
# Produce the non-materialized max sequence from materialized sequence quote.close
maxit = quote.close.grid_agg_max(7)
...
con.commit()