Data Browser
- Viewing Site
Sector 23 Code Bank
Logged in as:
Guest
Similar Topics...
Set width of anchor (a) in CSS
Specify SQL Query (Command) in Crystal Report
Custom .NET Responsive Html Table that is mobile-friendly
Civilization IV Will Not Run
Linq to SQL cannot generate DataContext with stored procedure containing a Temporary Table (#Temp
Rename Table Column Name for SQL
LINQ - Join problems
SQL Server Query to get Latest Backup Date
How to Update Statistics on a SQL Table
React Notes
NET 5 HttpPost Model null if too large and other issues
Ok Google, what does a total lunar eclipse look like
Image.Save: Value cannot be null. Parameter name: encoder
Run Civilization IV on Windows 7
The table type parameter must have a valid type name
JQuery Dialog not opening second time
Configuring new XP System to run .NET Web
Query SharePoint Document by Custom Field using API
Run SimCity 4 on Windows 7
Angular drop down select item with null value
Generic Audit of SQL Table
NET Export GridView to a CSV (that Excel can Actually Read
Run Heroes of Might and Magic III on Windows 7
SSRS - Comparing multi-value parameter to NULL crashes report viewer
Angular7 bind object to select dropdown example
mysql max_allowed_packet exceeded
Sql Server Statistics
string trim in sql server
Testing SQL Code without cache - SQL Server
sql server date parts
MySql Backslashes
Problems creating a foreign key in Sql Server
Syntax error in TextHeader of StoredProcedure (SqlServer 2005)
Insert SqlMembershipProvider User using SQL
Restore Mapping from Sql Server User to Login
Granting SQL user rights to start a SSIS Job
How to Truncate a SQL Server DateTime
Sql Server Identity Insert
Remove orphaned SQL Server Replication Publications
Kill all connections to SQL Server Database
Sql Server 2008 Comma Delimited List
SQL Server Rank/Partition
SQL Server 2008 will not shrink transaction log
SQL times out in web, but not in Management Studio
SQL Server 2008 Maintenance Cleanup Task to delete database backup files
How to Get all Recent SQL Calls to Database
SQL Server 2008 XML Example
SQL With Clause Example
How to convert SQL exceptions to more meaningful exceptions
Deadlocks in Sql Server 2008 R2
SQL Server Very Slow Filter on Bit
Sql Server 2008 varbinary(max) performance bug
Bulk Delete Many SQL Rows in Loop
SQL - distance between two coordinates
How to create a new database in SQL Server
MySQL Workbench export Fails with Connect Error
SQL - Convert DateTime to Local Time from UTC
Convert SQL DateTime to UTC
SQL exception thrown from stored procedure does not raise exception in C#
Link to File on Local Server from TreeView Web Page
Dynamically Build Template Column as a Reusable Server Control
DesignMode is always false in a Custom Server Control
SSRS Parameter default value is blank when deployed to server
.NET Upload Excel or CSV file to Server as DataSet or DataTable
How to get unique ClientId in Custom .NET Server Control
How to Log Off Windows Server 2012 with a mouse
Unable save Web Server Authentication Settings in Visual Studio 2019
LINQ - Order by multiple fields
Returning Multiple Aggregates in Group by in LINQ
Upload Multiple Files ASP.NET 4.0, Using HTML5 Input File and/or Drop Target
Validate two/multiple controls with CustomValidator
Multiple Angular Slickgrids on same page showing wrong data
SQL Server OR Clause Very Slow when Referencing Multiple Tables
I had
a
query
that
looked
like
this:
SELECT
* FROM
TABLE
A
JOIN
TABLE
B
ON A.Id = B.RefId
WHERE A.IntField = 1 OR B.DateField IS NOT
NULL
(
run
s in 150
second
s)
Note
that
the 'OR'
clause
references both
table
s
A
and B.
Table
B was tiny and
A
was huge, but the reality is
that
the following queries
run
almost instantly:
SELECT
* FROM
TABLE
A
JOIN
TABLE
B
ON A.Id = B.RefId
WHERE A.IntField = 1 (
run
s in 3
second
s)
SELECT
* FROM
TABLE
A
JOIN
TABLE
B
ON A.Id = B.RefId
WHERE B.DateField IS NOT
NULL
(
run
s in 3
second
s)
So why would combining them with 'OR' take the
query
time
from 3
second
s + 3
second
s to well over 150
second
s?
I think
SQL
Server
was doing
a
row
by
row
merge of the
results
meeting either condition
A
or B, and this was taking forever for whatever reason. Something to
do
with
A
and B being
different
table
s.
I
found
a
trick to make this
query
go
down to 6
second
s. The trick was to alter the fast subqueries so
that
they
return
distinct
results
. Then, use UNION ALL to combine them.
It
look
s
like
this when done:
SELECT
* FROM
TABLE
A
JOIN
TABLE
B
ON A.Id = B.RefId
WHERE A.IntField = 1
AND B.DateField IS
NULL
-- (if it happens to be NOT
NULL
, the
second
query
will catch it)
UNION ALL
SELECT
* FROM
TABLE
A
JOIN
TABLE
B
ON A.Id = B.RefId
WHERE B.DateField IS NOT
NULL
(
run
s in 6
second
s)
Created By: amos
10/3/2013 1:57:29 PM
Updated:
10/3/2013 1:57:58 PM