![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
ddl: create table srchPool(tid int primary key, taid int, s tynyint, uid tynyint); -- and sql server automatically creates a clustered index for the pk dml: insert into srchPool(taid,s,uid) select article_id, 99, 1484 from targetTBL where article_content LIKE '% presentation %'; insert into srchPool(taid,s,uid) select article_id, 55, 1484 from targetTBL where article_content LIKE '% demonstration %'; -- a few more similar queries ... The above insertion query TOOK about 2000ms to execute, too too slow, would be much faster if I insert the data sets into a temp tbl like select article_id, 99, 1484 into #srchPool(taid,s,uid) from targetTBL where article_content LIKE '% presentation %'; -- once its use is finished and drop it |
#3
| |||
| |||
|
|
Don Li (tatata9... (AT) gmail (DOT) com) writes: ddl: create table srchPool(tid int primary key, taid int, s tynyint, uid tynyint); -- and sql server automatically creates a clustered index for the pk The above insertion query TOOK about 2000ms to execute, too too slow, would be much faster if I insert the data sets into a temp tbl like select article_id, 99, 1484 into #srchPool(taid,s,uid) from targetTBL where article_content LIKE '% presentation %'; -- once its use is finished and drop it It depends. What takes time? Inserting the rows or finding them? Given that the condition requires a scan, I would place my bets at the latter. But just run the statements to test. In targetTBL is there an index on (article_content, article_id)? What is the data type and collation of article_content? -- Erland Sommarskog, SQL Server MVP, esq... (AT) sommarskog (DOT) se Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books... Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx- Hide quoted text - - Show quoted text - |
#4
| |||
| |||
|
|
I've added a non-clustered index to the targetTBl(article_content, article_id), article_content is varchar(896) and article_id is int. On collation for article_content, it uses "database default", which is SQL_Latin1. |
|
However, the scan is still taking too long, insertion of about 12 rows took about 7000ms. And I even added index hint. It's odd though yesterday and the day before yesterday, the same query ran at least 100% faster. |
#5
| |||
| |||
|
|
rows took about 7000ms. And I even added index hint. It's odd though yesterday and the day before yesterday, the same query ran at least 100% faster. |
#6
| |||
| |||
|
|
On 28 Nov., 01:12, Don Li <tatata9... (AT) gmail (DOT) com> wrote: rows took about 7000ms. And I even added index hint. It's odd though yesterday and the day before yesterday, the same query ran at least 100% faster. The question is: What has happened? Did anyone create a trigger onto your table? That's a good guess if inserted takes suddenly much longer. Bye, Manfred |
#7
| ||||
| ||||
|
|
Don Li (tatata9... (AT) gmail (DOT) com) writes: I've added a non-clustered index to the targetTBl(article_content, article_id), article_content is varchar(896) and article_id is int. On collation for article_content, it uses "database default", which is SQL_Latin1. OK, there are some spetacular differences between SQL collations + varchar and Windows collations or anything with nvarchar with that type of query. Don't really follow you here, could you elaborate a bit further on the |
|
However, the scan is still taking too long, insertion of about 12 rows took about 7000ms. And I even added index hint. It's odd though yesterday and the day before yesterday, the same query ran at least 100% faster. But it's not really the insertion that takes time, is it? I mean, if you the SELECT alone, it does not respond in 70 milliseconds, does it? Yeah, the SELECT, table scan thing sucks. |
|
Have you considered using full-text indexing? I'm using another technique for text data search, looks superior to |
|
-- Erland Sommarskog, SQL Server MVP, esq... (AT) sommarskog (DOT) se Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books... Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx |
#8
| |||
| |||
|
|
OK, there are some spetacular differences between SQL collations + varchar and Windows collations or anything with nvarchar with that type of query. Don't really follow you here, could you elaborate a bit further on the collations topic? |
#9
| |||
| |||
|
|
Don Li (tatata9... (AT) gmail (DOT) com) writes: OK, there are some spetacular differences between SQL collations + varchar and Windows collations or anything with nvarchar with that type of query. Don't really follow you here, could you elaborate a bit further on the collations topic? Consider these tables: CREATE TABLE sqlvarchar( a int NOT NULL IDENTITY, lotsoftext varchar(4000) COLLATE SQL_Latin_General1_CP1_CI_AS) CREATE TABLE sqlunicode( a int NOT NULL IDENTITY, lotsoftext nvarchar(4000) COLLATE SQL_Latin_General1_CP1_CI_AS) CREATE TABLE windowsvarchar( a int NOT NULL IDENTITY, lotsoftext varchar(4000) COLLATE Latin_General1_CI_AS) CREATE TABLE windowsunicode( a int NOT NULL IDENTITY, lotsoftext nvarchar(4000) COLLATE Latin_General1_CI_AS) Fill the tables with many rows. Then run queries like: SELECT * FROM tbl WHERE lotsoftext LIKE '%sometext%' You will find that the queries against sqlvarchar runs about seven times faster than the other queries. At least that is my experience. But as you already appears to be using SQL collation and varchar, that observation does not help you much. -- Erland Sommarskog, SQL Server MVP, esq... (AT) sommarskog (DOT) se Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books... Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx |
#10
| |||
| |||
|
|
Erland, I'm with you, thank you. Now, let's refer to a previous but related thread, http://groups.google.com/group/comp....7c382a0f8dbaa9 There you mentioned about cache, I searched BOL for more on the subject to almost no avail, googling gets something like "BPool (buffer pool) and MemToLeave", too theorical not practical. Any pointer for this? |
![]() |
| Thread Tools | |
| Display Modes | |
| |