English 中文(简体)
你们是否将这一简单回头换回来,以便重新开展工作?
原标题:Would you send this simple SQL back for rework?
  • 时间:2010-01-11 23:09:40
  •  标签:
  • sql
  • oracle

我们有一个网络应用程序,用户根据已经输入的参数进行临时查询。 我还要指出,答复时间对用户非常重要。

该网页根据所输入的参数,动态地构造一个执行结构。 例如,如果用户进入“企业单位”的“1”,我们就建造了这样的结构:

SELECT * FROM FACT WHERE 
BUSINESS_UNIT =  1 
--AND other criteria based on the input params

我发现,如果用户没有具体说明BUSINESS_ UNIT 建造了以下电梯:

SELECT * FROM FACT WHERE 
BUSINESS_UNIT LIKE  % 
--AND other criteria based on the input params

IMHO, 这不一定(如果不是严重的话)效率不高,因此,要求发送错误修改的代码,但因为我寄回重新工作的代码比其他人要高很多,我认为,我可能获得“选择”的声誉。

如果这是一个不适当的问题,因为它不是一个直接的编码问题,那么,让我知道,我将立即删除。 我感到非常困惑的是,是否允许或不允许这样的主观问题! 我感谢你们的答复。

ty


最新情况:

我正在使用一个Oracle数据库。

我的印象是,Oracle没有通过消除这一条件优化“LIKE %”,而使之效率较低。 可否确认?

最佳回答

虽然这看起来效率极低,但我刚刚在服务器中测试了SQ,而电梯优化器足以过滤它。

换言之,

SELECT * FROM FACT WHERE 
BUSINESS_UNIT LIKE  % 

以及

SELECT * FROM FACT

制定了相同的询问计划。 因此,尽管它确实看着哪一种微薄的气味,但并没有出现业绩差异(取决于你的银发动机一gues)。

这可能影响你决定退回。 我本人也许会这样,但如果你重新陷入了云层,那么,至少就业绩而言,你可能会有所放松。

问题回答

这两个问题完全不同(从结果组的角度来看)

SELECT * FROM FACT;

以及

SELECT * FROM FACT WHERE  
BUSINESS_UNIT LIKE  % ;

The first will return all rows, the second, if there are NULL values those rows will not be returned because anything compared to NULL is NULL 以及 therefore does not satisfy the predicate. This is how it would work in Oracle.

查询,附<代码> 缩略语 我称,它使表格完全扫描......

因此,如果是,我会设法重新处理这一提问,以适当方式处理这种局势——或至少处理。 我愿通过我们的“双轨”<>报告这个问题(我肯定会优先处理,但现在,这个问题会在某些地方出现,有人会纠正,当没有高优先处理问题的时候。”

SlectT* 是红旗。 具体列出查询的栏目清单。

我将回头来,我也同这个问题一样。

所有法典审查在某种程度上都是主观的。 标准应当基于若干因素。

  • 它是否发挥作用。

  • 它是否符合业绩、可维持性、可使用性和可扩展性的合理期望

虽然我没有测试这一特殊建筑——但我怀疑(正如你一样)这部法典将给你的服务器带来可怕的东西。 因此,业绩和可衡量性受到质疑。

作者希望发表一份备忘录,以便他/她能够把“和”之后的所有声明都附在后面。 将其改为“无选择”声明,如1==1,将有助于。 或者,它们可以略微增加工作,并明智地插入“其他地方”。

我要问,为什么不使用的内在变量(除非在特定情况下有很好的理由):

SELECT * FROM FACT WHERE 
BUSINESS_UNIT =  1 

为什么不:

SELECT * FROM FACT WHERE 
BUSINESS_UNIT = :bu




相关问题
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 ...