English 中文(简体)
优化查询:称职或加入?
原标题:Optimize a SQL query : call a function or do a join?

ORACLE数据库中最快的是什么?

在选择说明中要求一项功能,以重新计算每行的单一价值

SELECT field1, field2, F_GET_LIBELLE_STATUT( field2 ) FROM table1 WHERE ...

具有简单功能:

create or replace
FUNCTION "F_GET_LIBELLE_STATUT" (v_statut NUMBER) RETURN VARCHAR2 IS
tmpVar VARCHAR2(40);
BEGIN
   select libelle into tmpVar from t_statut_ope where id_statut = v_statut;
   RETURN tmpVar;
   EXCEPTION
     WHEN NO_DATA_FOUND THEN
       RETURN   ;
     WHEN OTHERS THEN
       -- Consider logging the error and then re-raise
       RAISE;
END f_get_libelle_statut;

还是加入其中?

Select a.field1, a.field2, b.libelle
FROM table1 a LEFT JOIN t_statut_ope b ON b.id_statut = a.field2
WHERE ...

如果我在选择和条款条件中讲到许多职能(或更多),那是同样答案吗?

感谢您的回答。

最佳回答

可在Kall做的任何工作都应在(*)上进行。

合并将永远比要求这一职能更快,因为固定业务总是比增长更快。 然后,在LQ和PL/SQL之间有流动的间接费用。 加上处理这些“诺瓦塔”——FOUND”例外的间接费用,这些例外是真正的例外,因为差距是预期和容忍的。 最后,由于你提供了它所需要的全部信息,优化机构将选择一个更完善的计划。


<(*)>,我回答了这个问题,我回答了这个问题,我回答这个问题时着重谈到所举的例子。 如果我们能够获得我们所需要的数据,则我们就应该这样做。 但我想谈谈根本问题:为什么Oracle支持使用询问中的职能? 由于有时我们需要做事情,我们能够做成车。

这里使用的是要求履行职能的案件(主要是通过<条码>(<<>>>>>>代码/代码>电话)而不是使用结合(或诸如在线观点、附则条款等其他结构):

  1. Query is dynamic. Dynamic SQL requires PL/SQL so a function is yer only man here.
  2. Row generation. Using PL/SQL to split the input into multiple strings (such as CSV tokenizing) or perhaps to spawn data, not from a table. Occasionally still valid but regex support and the nifty CONNECT BY LEVEL <= N trick have binned the more common usages.
  3. The data is encapsulated behind a PL/SQL API so a function is all we can call.
  4. For some bizarre reason we can only get the performance we need by using PL/SQL to implement a filter or a look-up. Apparently. To be honest I can t ever remember a case where I had to do this and it worked (although I ve had a few cases where turning a pipelined function into a subquery or inline view improved performance). Maybe I ve led a sheltered life. Certainly, I would welcome benchmarked citations for counter-examples.
问题回答

职能方法最优化的情况将很少,否则我将不使用。 数据库是设计的,因此应该成为你们的第一选择。

你们利用这2个不同询问发现的是什么?

在我的经验中,参加人数比一项职能高出十倍。 至少当你们在获得另一个问询/表/职务时。 每项职能都需要评估,合并可能产生更大的数据集,但可以做得更好,因为它只需要加入(关键)表格,而表格相当快。

OR忘记了外部,并提出了在选定名单中翻译的选定声明[这有时是外层空间加入的更快]:

SELECT field1, field2
, (select libelle from t_statut_ope b where b.id_statut = a.field2) libelle
FROM table1 a
WHERE 1=1
;




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

How to make a one to one left outer join?

I was wondering, is there a way to make a kind of one to one left outer join: I need a join that matches say table A with table B, for each record on table A it must search for its pair on table B, ...

Insert if not exists Oracle

I need to be able to run an Oracle query which goes to insert a number of rows, but it also checks to see if a primary key exists and if it does, then it skips that insert. Something like: INSERT ALL ...

How can I store NULLs in NOT NULL field?

I just came across NULL values in NOT-NULL fields in our test database. How could they get there? I know that NOT-NULL constraints can be altered with NOVALIDATE clause, but that would change table s ...

Type reference scope

I m studying databases and am currently working on a object-relational DB project and I ve encountered a small problem with the number of possible constraints in an object table. I m using "Database ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

热门标签