Showing posts with label million. Show all posts
Showing posts with label million. Show all posts

Tuesday, March 27, 2012

Advice on indexes

I have a table (detail) with 4 columns and over 30 million rows .
Say the columns are called ColA, ColB, ColC, ColD

ColA and ColB form a foreign key as this table is a 'detail' table for another master table in the database (master). The master table uses these two columns as its primary key.
To speed up joins between the two tables I have created an index over ColA and ColB

I frequently need to join the two tables together and so most of my queries are of the form:

SELECT master.*, detail.ColC, detail.ColD FROM master JOIN detail
ON master.ColA = detail.ColA and master.ColB = detail.ColB
WHERE master.ColA = @.valA
ORDER BY master.ColB, detail.ColC

This could return up to 60000 rows for a specific value of @.valA.
This is usually a sub-query that feeds directly into another query or a temporary table.

However, I also quite often need to filter the details further by ColC so I have queries like

SELECT master.*, detail.ColC, detail.ColD FROM master JOIN detail

ON master.ColA = detail.ColA and master.ColB = detail.ColB

WHERE master.ColA = @.valA AND detail.ColC = @.valC

ORDER BY master.ColB

The results set from this could be just a few hundred rows depending on @.valC

I clearly have a requirement to have an index across ColA, and ColB, presumably as the clustered index.

My question is how to speed up queries that involve ColC.
Do I create another index across ColA, ColB and ColC or just ColC by itself?
Will an index just on ColC make use of the the clustered index on the other columns?
Should I make the clustered index cover ColA, ColB and ColC instead ? etc ..

I am using SQL Express and am approaching the 4GB limit and this table and another one similar to it account for 96% of the database size.
The four columns in the detail table are all integer types and so don't take up much space per row. I am worried that a wide index will significantly add to the storage space per row and therefore significantly reduce the amount of data I can store in the database.

Any advice would be appreciated.

You defintely do not ever want to create one index that is a subset of another as you asked, ie. do not create two indexes on

ColA, ColB

ColA, ColB, ColC

The one on ColA, ColB, ColC does everything that the first one does, so it is all you need.

In your case it sounds like a clustered index on ColA, ColB, ColC should be all you need. Leaving out one column won't make much difference to the size. The size will be affected by the fillfactor and the fragmentation level of the index, so you should rebuild the index from time to time (how often depends on the nature of your updates) with a fillfactor of 100%, although a high fillfactor will increase the possibility that some updates will be slower.

|||Thanks for that.

I have done as you have said and created an index across all three columns and I am happy with both the speed of the queries and the size of the database.sql

Advice Needed On Very Large Full Text Indexes

I'm currently building a product that will need to index and search roughly
500 million documents (perhaps more). Currently I have about 60 million
documents in the index (table size about 100GB and index size about 35GB)
Performance is (obviously) getting worse and I doubt my current architecture
will support the needed growth and still provide the required speed.
Documents are added 24x7 at the rate of 100's per minute (roughly 250,000
new ones each day). Plus, due to the search requirements, I had to clear
the noise file. I've been thinking of doing table partitioning (using
2005), creating indexed views and then using multiple full-text indexes to
query the data (however, of course, I will not be able to rank effectively
then).
So, I'm curious if any one else has this type of volume and has come up with
a solid solution. Appeciate any ideas.
I should also mention that I'm looking for short term consulting help on
this, as well as a full-time position - so while I'm grateful for free
suggestions from this board, should anyone be looking for work, please
contact me as well (company located in New Jersey).
Thanks!
Joel
Partitioning works, but you need to have well defined partitions which the
data and the queries will align itself with.
For example if you are querying by a search phrase and your
buckets/partitions are by date partitioning won't help you. If you are
partitioning by date you will get some advantages if you have time
dependencies. For example in Google, if you query on your name
http://www.google.com/search?sourcei...=Joel+Macaluso
you'll notice 70,100 hits. Then as you move to other pages you'll notice
that the number goes down to 69,900. What has happened is the first hit is
on one server which has mainly new stuff. The subsequent queries hit the
bigger archive which represents the totality. The time partition works for
them even though most of their queries are have no real time dependency, ie
web pages from 2001.
You might want to analyze your queries looking for colocants - words which
are search for as a unit - Bacon and Eggs, Sonny and Cher, George Bush.
Likewise you might choose not to index hapax legomenon, dis legomenon, tris
legomenon or even tetrakis legomenon. You also might want to look at words
over a certain length and not index them.
One other point that you aren't answering is while I know about your
indexing requirements - what are you querying requierments like? IE How may
queries per day/min/sec.
I am facing some of the same problems where I work now. I'd be interested in
following up with you on this one. I'm in NJ as well.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Joel Macaluso" <jmacaluso@.digitalgrit.com> wrote in message
news:%23OjwJkXGGHA.1088@.tk2msftngp13.phx.gbl...
> I'm currently building a product that will need to index and search
> roughly 500 million documents (perhaps more). Currently I have about 60
> million documents in the index (table size about 100GB and index size
> about 35GB) Performance is (obviously) getting worse and I doubt my
> current architecture will support the needed growth and still provide the
> required speed.
> Documents are added 24x7 at the rate of 100's per minute (roughly 250,000
> new ones each day). Plus, due to the search requirements, I had to clear
> the noise file. I've been thinking of doing table partitioning (using
> 2005), creating indexed views and then using multiple full-text indexes to
> query the data (however, of course, I will not be able to rank effectively
> then).
> So, I'm curious if any one else has this type of volume and has come up
> with a solid solution. Appeciate any ideas.
> I should also mention that I'm looking for short term consulting help on
> this, as well as a full-time position - so while I'm grateful for free
> suggestions from this board, should anyone be looking for work, please
> contact me as well (company located in New Jersey).
> Thanks!
> Joel
>

Tuesday, March 20, 2012

Advantages?

I would welcome opinions on whether FTS would help in our scenario.
The table has about 28 million rows and has about 10,000 rows added every
morning in an intensive batch process. Then another batch query process is
run that looks for partial name matches.
Eight of the fields we query against are char or varchar, all with single
words.
Sample query: SELECT casenumber FROM table WHERE fname LIKE 'j%' AND lname
LIKE 'smi%'. Rreturns 55,874 rows in 7 seconds in QA.
I am also concerned about time to populate FT index every day.
Machine is dual Xeon 3.2 with 4GB ram, OS on RAID1 & SQL data on RAID5. Win
2003 Server and SQL2000, with SQL2005 later this year.
Thanks much!
Wow! That's fantastic speed for a like. I'd try change tracking. IIRC on a
similar machine I was able to hit 2000 rows per minute with SQL 2000.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Bil Click" <BilClick@.discussions.microsoft.com> wrote in message
news:FFF888F6-8310-4B1F-83B0-399830C17F53@.microsoft.com...
>I would welcome opinions on whether FTS would help in our scenario.
> The table has about 28 million rows and has about 10,000 rows added every
> morning in an intensive batch process. Then another batch query process is
> run that looks for partial name matches.
> Eight of the fields we query against are char or varchar, all with single
> words.
> Sample query: SELECT casenumber FROM table WHERE fname LIKE 'j%' AND lname
> LIKE 'smi%'. Rreturns 55,874 rows in 7 seconds in QA.
> I am also concerned about time to populate FT index every day.
> Machine is dual Xeon 3.2 with 4GB ram, OS on RAID1 & SQL data on RAID5.
> Win
> 2003 Server and SQL2000, with SQL2005 later this year.
> Thanks much!
|||Thanks Hilary, but do you think a Full Text search would be faster searching
on single words?
"Hilary Cotter" wrote:

> Wow! That's fantastic speed for a like. I'd try change tracking. IIRC on a
> similar machine I was able to hit 2000 rows per minute with SQL 2000.
> --
> Hilary Cotter
> Looking for a SQL Server replication book?
> http://www.nwsu.com/0974973602.html
> Looking for a FAQ on Indexing Services/SQL FTS
> http://www.indexserverfaq.com
> "Bil Click" <BilClick@.discussions.microsoft.com> wrote in message
> news:FFF888F6-8310-4B1F-83B0-399830C17F53@.microsoft.com...
>
>
|||It will be for larger tables. I am not sure where the cut off it - i.e.
20,000 rows or 2 million.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Bil Click" <BilClick@.discussions.microsoft.com> wrote in message
news:FDFBA954-00ED-4444-A7EF-2B5547510343@.microsoft.com...[vbcol=seagreen]
> Thanks Hilary, but do you think a Full Text search would be faster
> searching
> on single words?
> "Hilary Cotter" wrote:

Monday, March 19, 2012

Advanced SQL tutorials in Problem/Answer format

I'd like some challenging practice with SQL; general SQL-92 or MS specific (sql server or access).
There's a million sources on the Web, but most are like reference manuals. I already have MSDN with my VS 6.0 and .Net, as well as help files for 3 different versions of Access. I'm looking for something set up more like assignments or challenges. I found a couple sites like this:
SqlZoo.net and SQLCourse.com

SqlZoo has too many mistakes and vague questions. SQLCourse is pretty good, but no advanced stuff (some multiple Joins, subqueries, calculated fields and such). I like the idea of having the same related tables that you keep solving different problems with. This is more like a real-world situation. I would think that there would be a lot of question/answer tutorials for the MS supplied sample db's (Northwind, Pubs, etc.), but I haven't found any.

These forums are full of good questions posed by people, but they always concern unfamiliar data sources and I have to slog through the posts with my slow dial-up connection. I would rather do one big download and work at the problems offline.
Any suggestions?if you want the same related tables that you keep solving different problems with, your best bet is to search for the more common databases like northwind and sakila, perhaps by throwing several of their tables names into a search

if you want advanced question/answers, i humbly offer my own (the actual articles are on the techtarget.com site)

see http://r937.com/sqlate.cfm|||Thanks. There's a lot of good questions in one spot; I can easily download a bunch of those pages. Since the questions are all at the top of the pages, I can read them without seeing the answers. You helped save me a lot of searching time. If I do find some Northwind-based question tutes, I'll post the link.
Thanks again.|||Ahh, I find I learn more than enough from here :p
Just subscribe to SQL/Access threads that you are interested in.
I've knocked up a test database purely for solving problems on here -
trying to recreate peoples problems and see if I can solve them.

It's often a really good way to learn when you're given an unfamiliar problem, because you try and break it down into a generic solution (which means you can use it again later!).

There's my 2 cents. :cool: