Showing posts with label field. Show all posts
Showing posts with label field. Show all posts

Monday, March 26, 2012

Performance question

Hello there
I have two tables i match with them. the field i match is none clustered
index.
When i make INNER JOIN between them it takes less then left or right join.
And inspite both of the fields have index the execution plan use hash join.
Whay it is like that?The reason for this is the way that the query processer works internally.
The Inner join will select rows which are in both of the two tables
mentioned in the join.
The left join will select all the rows from the left table, regardless of if
they exist in the right hand table.
If you look at the execution plans it's likely that you'll see an index s
for the inner join and an index scan for the left join.
Regards
Colin Dawson
www.cjdawson.com
"Roy Goldhammer" <roy@.hotmail.com> wrote in message
news:uHNGAOrZGHA.1348@.TK2MSFTNGP05.phx.gbl...
> Hello there
> I have two tables i match with them. the field i match is none clustered
> index.
> When i make INNER JOIN between them it takes less then left or right join.
> And inspite both of the fields have index the execution plan use hash
> join.
> Whay it is like that?
>|||Roy Goldhammer (roy@.hotmail.com) writes:
> I have two tables i match with them. the field i match is none clustered
> index.
> When i make INNER JOIN between them it takes less then left or right
> join. And inspite both of the fields have index the execution plan use
> hash join.
> Whay it is like that?
Since neither tables, nor indexes, nor indication of table sizes were
included, I can only respond in general terms.
SQL Server has three differnt strategies to join tables: loop join, merge
join and hash join.
With a loop join, SQL Server finds rows in one table, and for each row
looks up a row in the other table.
With a merge join, SQL Server scans both tables in parallell. Merge join
presumes that the inputs are sorted on the same value.
With a hash join, SQL Server scans both tables and builds a hash table
that is then used for lookup.
Loop join is good when the other table is large, and only a handful row
will be hit. But if many rows are to be selected, the loop join is
expensive, and it's cheaper to scan once.
SQL Server does not know beforehand which will be the most expensive,
but the optimizer computes estimates from the statistics sampled about the
data.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

Wednesday, March 21, 2012

Performance problems ADODB connection

Hi,
My programm (24/7 - VB6) is connected to a MSSQL Database with only one
table where data is stored with a time_stamp field as index. Automatically
the software updates each 2 minutes the table and with the same frequency
querys and display data for the last 3 days.
I have also one function where the user can select the amount of the
displayed data. When the software is working for a few ws in automatic
mode (allways 3 day - data displaying) and the a user start a request to
display all the datas in the table, at the first time the query is failing
with timeout and at the second request is returning the requested data. I
use the ADODB Connection object with client side cursor which is used in a
ADODB.Recordset Open method to return the data.
Has anybody a ideea why is the first time query failing and /or how to
prevent this ?
Thank you !Hi
It appears to be contention problem.Try using lower level locks and if
needed you may use NOLOCK HINT with the select query in backend if possible
.
Regards
R.D
"Marius Cecon" wrote:

> Hi,
> My programm (24/7 - VB6) is connected to a MSSQL Database with only one
> table where data is stored with a time_stamp field as index. Automatically
> the software updates each 2 minutes the table and with the same frequency
> querys and display data for the last 3 days.
> I have also one function where the user can select the amount of the
> displayed data. When the software is working for a few ws in automatic
> mode (allways 3 day - data displaying) and the a user start a request to
> display all the datas in the table, at the first time the query is failing
> with timeout and at the second request is returning the requested data. I
> use the ADODB Connection object with client side cursor which is used in a
> ADODB.Recordset Open method to return the data.
> Has anybody a ideea why is the first time query failing and /or how to
> prevent this ?
> Thank you !
>
>|||Hi RD,
Thank you for trying to help me.
I've changed my select query adding the NOLOCK hint but is no change in the
behaviour.
They are no multiuser access to the table, my programm is the only one
connected to the table over a Connection object created at programm start
and closed when programm ends.
Marius.
"R.D" <RD@.discussions.microsoft.com> schrieb im Newsbeitrag
news:AF677CC9-1EB4-4EA9-A588-BC7FA12E4E09@.microsoft.com...
> Hi
> It appears to be contention problem.Try using lower level locks and if
> needed you may use NOLOCK HINT with the select query in backend if
possible.
> Regards
> R.D
> "Marius Cecon" wrote:
>
Automatically
frequency
automatic
failing
I
a|||On Wed, 31 Aug 2005 09:33:20 +0200, "Marius Cecon" <m.cecon@.hydrovision.de>
wrote:
in <ugELI5frFHA.2076@.TK2MSFTNGP14.phx.gbl>

>Hi,
>My programm (24/7 - VB6) is connected to a MSSQL Database with only one
>table where data is stored with a time_stamp field as index. Automatically
>the software updates each 2 minutes the table and with the same frequency
>querys and display data for the last 3 days.
>I have also one function where the user can select the amount of the
>displayed data. When the software is working for a few ws in automatic
>mode (allways 3 day - data displaying) and the a user start a request to
>display all the datas in the table, at the first time the query is failing
>with timeout and at the second request is returning the requested data. I
>use the ADODB Connection object with client side cursor which is used in a
>ADODB.Recordset Open method to return the data.
>Has anybody a ideea why is the first time query failing and /or how to
>prevent this ?
>Thank you !
Try setting the connection object's CommandTimeout property to zero (infinit
e)
just prior to the recordset Open method.
Stefan Berglund

Tuesday, March 20, 2012

Performance problem ?

Hi all,

I have a table "Customer"

And field names call ForeName varchar(30),Surname varchar(30)

When i select

SELECT c.SURNAME + ', ' + c.FORENAME as ID, c.SURNAME + ', ' + c.FORENAME as label

FROM Customer c

where c.SURNAME + ', ' + c.FORENAME='Perera, N'

It will give me the result writhing a second.

Now the problem is in our company we have moved to a different database table structure from last week.

now my "Customer" table has got a same field name but different data type like bellow.

ForeName nvarchar(Max),Surname nvarchar(Max)

So when I give the same select sql statement like previously mentioned, it takes more than 8 seconds time?

How come this happens? Because we have the same amount of data from old database structure and new structure?

Any Idea ?

Regards

sujithf

If you use nvarchar(max) field you couldn't index it. May be in old structure you had indexes.|||

Thaks for your response ,

How do i know wheater my table field indexed or not ,

i have no idea abt indexing ?

can you please explain it bit more ?

i am bit new to sql server 2005

regards

sujithf

|||

You could review indexes using following sp:

sp_helpindex '<your table name>'

But if you already have nvarchar(max) fields, if don't have index, because:

Columns that are of the large object (LOB) data types ntext, text, varchar(max), nvarchar(max), varbinary(max), xml, or image cannot be specified as key columns for an index. Also, a view definition cannot include ntext, text, or image columns, even if they are not referenced in the CREATE INDEX statement.

Also I think, that it's bad idea to use nvarchar(max) as field data type for Surname, Forename. Is it really possible, that surname or forename could be greater than 4000 characters? nvarchar(max) data type designed for very large amount of data and stored outside of table.

|||

Hi.

many thanks for your valuable comments ,

i checked using your command, it says object does not have any indexes,

Yes i am also agree with you,because its wasting space by specifying Nvarchar(max) for surname+forename

but our company hired a third party company to migrate from old database structure to new structure,

i think we have to contact third party company for this matter.

so do you think , this sql query 7 seconds times slow in a new structure because of the datatype nvarchar(max) ?

what is your sugestions ?

regards

sujith

|||

I don't have large table, but It make test on table Person.Contact from AdventureWorks sample Database. This table has ~20,000 rows. I ran following query:

select FirstName+', '+MiddleName from Person.Contact where FirstName+', '+MiddleName = 'Frances, B.'

If both fields are nvarchar(50) without indexes, query time ~0,06s

If both feidsl are nvarchar(max), query time ~0,2s

So, i think, we have negative influence of max data type.

Also, I think, that better use following query:

select FirstName+', '+MiddleName from Person.Contact where FirstName='Frances' and MiddleName = 'B.'

and create indexes

|||

thank you so much for your effort to sort out my problem,

and finally can you provide me a example, that how to index the table ?

or can you provide me a articles to learn how to index tables and field ?

cos i really like to learn new stuff in sql server 2005

thank you again

sujithf

|||

CREATE INDEX article: http://msdn2.microsoft.com/en-us/library/ms188783.aspx. At the end of this article, you could find good examples

I suggest you to download latest version of BOL: http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx

|||

I think the problem is that if you are using max then by default the value is not stored on the data page but rather a 16-byte root pointer instead. To compare to the value it has to follow this pointer and load the text itself (more IO therefore slower).

It is possible to change this by using sp_tableoption to set the "large value types out of row" option to 0 but then all the values can only add up to a size of 8000 bytes (minus I would suspect the other data in the row). Sort of destroys the reason for not just using the smaller 1 to 4000 value (4000 nvarchar is 8000 bytes).

The problem with the max data types is that they are a new feature and everyone wants to use them without understanding the impact. They are really suposed to store large data that you do not generally expect to directly search (documents, free form commentary, images). That is what Full Text Search and the new xml indexes are for (to build search indices on some of the data types stored in this format).

As mentioned earlier there is no reason for expanding the fields in the way they have unless they can argue that people are going to have names of that length. I am particularly intrigued by the fact that you seem to only be storing the first initial in this enourmous first name field.

I would probably also be tempted to compare the fields individually rather than concatonating them if you are sure the break will always be (otherwise you have comma insertions issues anyway).

|||

Thank you both of you Dhericean + Konstantin Kosinsky

for your valuable time to consider my problem.

regards

sujithf

Monday, March 12, 2012

Performance penalty for LIKE when I really mean Equal?

Hi,
I have a situation where I can retrieve either all the rows in a table or
just some of them based on a "type" field in the row. The type of the rows
to select is passed as a parm to the method that retrieves the rows. If the
calling program wants the whole table it passes String.Empty as the type.
I was thinking of having one parameterized SQL statement like this...
SELECT * FROM T1 WHERE T1.TYPE LIKE @.Type
I'll append '%' to whatever "type" is passed the method. So if the calling
routine wants all records, LIKE '%' should return all rows. If the User
passes 'OT' (assuming a two character type code) I should still get all the
'OT' rows from the passed parm of
'OT%'.
Will I suffer a performance penalty by doing this, or is the query optimizer
smart enough to figure out that for a two character field, LIKE 'OT%' is th
e
equivalent of = 'OT'?
Thanks.
BBMFor prefix criteria (i.e. where the wildcard character is not used at the
beginning of the search argument), the query optimizer can take advantage of
indexes if the column used in the LIKE expression is indexed.
ML|||If @.Type is NULL, then the following will return all rows without evaluating
the like comparison:
SELECT * FROM T1 WHERE (@.Type Is Null) or (T1.TYPE LIKE @.Type)
"BBM" <bbm@.bbmcompany.com> wrote in message
news:E8437BCA-E0D4-4D1D-9A98-5F62A95938BE@.microsoft.com...
> Hi,
> I have a situation where I can retrieve either all the rows in a table or
> just some of them based on a "type" field in the row. The type of the
> rows
> to select is passed as a parm to the method that retrieves the rows. If
> the
> calling program wants the whole table it passes String.Empty as the type.
> I was thinking of having one parameterized SQL statement like this...
> SELECT * FROM T1 WHERE T1.TYPE LIKE @.Type
> I'll append '%' to whatever "type" is passed the method. So if the
> calling
> routine wants all records, LIKE '%' should return all rows. If the User
> passes 'OT' (assuming a two character type code) I should still get all
> the
> 'OT' rows from the passed parm of
> 'OT%'.
> Will I suffer a performance penalty by doing this, or is the query
> optimizer
> smart enough to figure out that for a two character field, LIKE 'OT%' is
> the
> equivalent of = 'OT'?
> Thanks.
> BBM|||Thanks for the tip. I'll try this.
"JT" wrote:

> If @.Type is NULL, then the following will return all rows without evaluati
ng
> the like comparison:
> SELECT * FROM T1 WHERE (@.Type Is Null) or (T1.TYPE LIKE @.Type)
>
> "BBM" <bbm@.bbmcompany.com> wrote in message
> news:E8437BCA-E0D4-4D1D-9A98-5F62A95938BE@.microsoft.com...
>
>

Friday, March 9, 2012

performance on the join

I know that join on an integer field is faster than join on varchar field.
What if I cast the fields to integer within the join clause,
ex. JOIN CAST(tableA.field AS int) = CAST(tableB.field AS int)
would this speed up my query?
Thanks,
CulamNot very likely, since -- even if there are indexes on these columns -- an
explicit conversion pretty much guarantees a scan.
Did you try it? Did you compare execution plans (both real and estimated),
cpu/reads/statistics i/o, etc?
If all the data is integer, why is the column still defined as varchar?
"culam" <culam@.discussions.microsoft.com> wrote in message
news:0D47D119-344A-419E-A5EB-EA44B06F1F88@.microsoft.com...
>I know that join on an integer field is faster than join on varchar field.
> What if I cast the fields to integer within the join clause,
> ex. JOIN CAST(tableA.field AS int) = CAST(tableB.field AS int)
> would this speed up my query?
> Thanks,
> Culam
>