What is index in SQL? Can you explain or reference to understand clearly?
Where should I use an index?
I searched in Stack Overflow, but it is still not clear to me.
My specific concern is related to the performance of a clustered index on a reference table that has many rapid inserts and deletes.
Table 1 "Collection" collection_pk int (among other fields)
Table 2 "Item" item_pk int (among other fields)
Reference Table "Collection_Items" collection_pk int, item_pk int (combined primary key)
Because the primary key is composed of both pks, a clustered index is created and the data physically ordered in the table according to the combined keys.
I have many users creating and deleting collections and adding and removing items to those collections very frequently affecting the "Collection_Items" table, and its clustered index.
QUESTION PART: Since the "Collection_Items" table is so dynamic, wouldn't there be a big performance hit on constantly resorting the table rows because of the clustered index ?
If yes, what should I do to minimize this ?
Given a 1*N matrix or an array, how do I find the first 4 elements which have the same value and then store the index for those elements?
PS:
I'm just curious. What if we want to find the first 4 elements whose value differences are within a certain range, say below 2? For example, M=[10,15,14.5,9,15.1,8.5,15.5,9.5], the elements I'm looking for will be 15,14.5,15.1,15.5 and the indices will be 2,3,5,7.
We're doing a whitelabel site, which mustn't be google indexed.
Does anyone know a tool to check if the googlebot will index a given url ?
I've put <meta name="robots" content="noindex" /> on all pages, so it shouldn't be indexed - however I'd rather be 110% certain by testing it.
im using this sql query to create an index:
$query = "CREATE INDEX id_index2
ON countries(geoname_id, name)";
but how do i update the index when new entries are added?
should i run a php script with the update query in CRON and run it every night?
is this best practice for automated index updating?
Following code:
<?php
$test_array = array();
$test_array['string_index'] = "data in string index";
$test_array[] = "data in index 0";
$test_array[] = "data in index 1";
$test_array[] = "data in index 2";
foreach($test_array as $key => $val)
{
if($key != 'string_index')
{
echo $val."<br>";
}
}
?>
gives result:
data in index 1
data in index 2
Question is - where is "data in index 0"??? How to get elements from numeric indices 0-n?
Also if I change 'string_index' to something else which doesn't exist, it echoes everything except [0]. Plz, explain me this.
Thnx in advance
I've done something like this in order to use on duplicate key update:
CREATE UNIQUE INDEX blah on mytable(my_col_to_make_an_index);
and its worked just fine. I'm just not sure what the purpose of the index name is -- in this case 'blah'. The stuff I've read says to use one but I can't fathom why. It doesn't seem to be used in queries, although I can see it if I export the schema.
So ... what purpose does the index name serve? If it helps the line in the CREATE TABLE ends up looking like:
UNIQUE KEY `clothID` (`clothID`)
Hello,
Is there any way to load an existing index into an instance of MemoryIndex?. I have an application which uses Hibernate Search so I can use index() in FullTextEntityManager instance to index an object. I'd like to recover back the created index and insert it into a MemoryIndex instance to execute several queries over it.
Is it possible?
Thanks.
Say I have a 2D array of random boolean ones and zeroes called 'lattice', and I have a 1D array called 'list' which lists the addresses of all the zeroes in the 2D array. This is how the arrays are defined:
define n 100
bool lattice[n][n];
bool *list[n*n];
After filling the lattice with ones and zeroes, I store the addresses of the zeroes in list:
for(j = 0; j < n; j++)
{
for(i = 0; i < n; i++)
{
if(!lattice[i][j]) // if element = 0
{
list[site_num] = &lattice[i][j]; // store address of zero
site_num++;
}
}
}
How do I extract the x,y coordinates of each zero in the array? In other words, is there a way to return the indices of an array element through referring to its address?
I have a Lucene index that contains a field called 'Name'.
I escape all special characters before inserting a value into my index using QueryParser.Escape(value).
In my example I have 2 documents with the following names respectively:
Test
Test (Test)
They get inserted into my index as such (I can confirm this using Luke):
[test]
[test] [\(test\)]
I insert these values as TOKENIZED and using the StandardAnalyzer.
When I perform a search, I use the QueryParser.Escape(searchString) against my search string input to escape special characters and then use the QueryParser with my 'Name' field and the StandardAnalyzer to perform my search.
When I perform a search for 'Test', I get back both documents in my index (as expected). However, when I perform a search for 'Test (Test)', I am getting back both documents still.
I realize that in both examples it matches on the 'test' term in the index, but I am confused in my 2nd example why it would not just pull back the document with the value of 'Test (Test)' because my search should create two terms:
[test] and [\(test\)]
I would imagine it would perform some sort of boolean operator where BOTH terms must match in that situation so I would get back just one record.
Is there something I am missing or a trick to make the search behave as desired?
I'm not intimately familiar with CCK but I have a one-time custom setup and know that I could get some performance gains if I created indexes and changed the field type and length of some of the fields in my CCK table. Is it save to modify this table at all or will I end up destroying something in the process?
Thanks
We need to be able to do a 'sort by relevance' search of a database for our application, but Googling 'sort by relevance custom search' doesn't do much good other than seeing Google Custom Search a 1000 times. It's a Cocoa CoreData database (double alliteration) if that matters. Thanks!
So, I have this funny requirement of creating an index on a table only on a certain set of rows.
This is what my table looks like:
USER: userid, friendid, created, blah0, blah1, ..., blahN
Now, I'd like to create an index on:
(userid, friendid, created)
but only on those rows where userid = friendid. The reason being that this index is only going to be used to satisfy queries where the WHERE clause contains "userid = friendid". There will be many rows where this is NOT the case, and I really don't want to waste all that extra space on the index.
Another option would be to create a table (query table) which is populated on insert/update of this table and create a trigger to do so, but again I am guessing an index on that table would mean that the data would be stored twice.
How does mysql store Primary Keys? I mean is the table ordered on the Primary Key or is it ordered by insert order and the PK is like a normal unique index?
I checked up on clustered indexes (http://dev.mysql.com/doc/refman/5.0/en/innodb-index-types.html), but it seems only InnoDB supports them. I am using MyISAM (I mention this because then I could have created a clustered index on these 3 fields in the query table).
I am basically looking for something like this:
ALTER TABLE USERS ADD INDEX (userid, friendid, created) WHERE userid=friendid
I recently decided to crawl over the indexes on one of our most heavily used databases to see which were suboptimal. I generated the built-in Index Usage Statistics report from SSMS, and it's showing me a great deal of information that I'm unsure how to understand.
I found an article at Carpe Datum about the report, but it doesn't tell me much more than I could assume from the column titles.
In particular, the report differentiates between User activity and system activity, and I'm unsure what qualifies as each type of activity.
I assume that any query that uses a given index increases the '# of user X' columns. But what increases the system columns? building statistics?
Is there anything that depends on the user or role(s) of a user that's running the query?
Hi,
I converted an old sql server database from 2000 to 2005 and forgetten to add old indexes to the new db.
is there any way to copy the old indexes to the new db?
any help?
Hi,
what is index in sql can u explain or any reference to understand clearly. where should i use the index. I search in stackoverflow but it is not clear for me. thank you
I need to check if this index not exist in specific table name not in all tables
because this select statement select all indexes under this condition.
IF NOT EXISTS (SELECT name from sysindexes WHERE name = 'IDX_InsuranceID')
CREATE NONCLUSTERED INDEX [IDX_InsuranceID] ON [dbo].[QuoteInsurances]
(
[InsuranceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
GO
Thanks,
Hi there!
I have this drupal website that revolves around a document database. By design you can only find these documents by searching the site. But I want all the results to be indexed by Googlebot and other crawlers, so I was thinking, what if I make a page that lists all the documents, and then tell the robots to visit the page to index all my documents..?
Is this possible, or is there a better way to do it?
Hi,
I was watching the Profiler on a live system of our application and I saw that there was an update instruction that we run periodically (every second) that was quite slow. It took around 400ms every time.
The query includes this update (which is the slow part)
UPDATE BufferTable
SET LrbCount = LrbCount + 1,
LrbUpdated = getdate()
WHERE LrbId = @LrbId
This is the table
CREATE TABLE BufferTable(
LrbId [bigint] IDENTITY(1,1) NOT NULL,
...
LrbInserted [datetime] NOT NULL,
LrbProcessed [bit] NOT NULL,
LrbUpdated [datetime] NOT NULL,
LrbCount [tinyint] NOT NULL,
)
The table has 2 indexes (non unique and non clustered) with the fields by this order:
* Index1 - (LrbProcessed, LrbCount)
* Index2 - (LrbInserted, LrbCount, LrbProcessed)
When I looked at this I thought that the problem would come from Index1 since LrbCount is changing a lot and it changes the order of the data in the index.
But after desactivating index1 I saw the query was taking the same time as initially.
Then I rebuilt index1 and desactivated index2, this time the query was very fast.
It seems to me that Index2 should be faster to update, the order of the data shouldn't change since the LrbInserted time is not changed.
Can someone explain why index2 is much heavier to update then index1?
Thank you!
I have a high-demand transactional database that I think is over-indexed. Originally, it didn't have any indexes at all, so adding some for common processes made a huge difference. However, over time, we've created indexes to speed up individual queries, and some of the most popular tables have 10-15 different indexes on them, and in some cases, the indexes are only slightly different from each other, or are the same columns in a different order.
Is there a straightforward way to watch database activity and tell if any indexes are not hit anymore, or what their usage percentage is? I'm concerned that indexes were created to speed up either a single daily/weekly query, or even a query that's not being run anymore, but the index still has to be kept up to date every time the data changes.
In the case of the high-traffic tables, that's a dozen times/second, and I want to eliminate indexes that are weighing down data updates while providing only marginal improvement.
I am using SQL Server 2008 and we are using the DMV's to find missing indexes. However, before I create the new index I am trying to figure out what proc/query is wanting that index. I want the most information I can get so I can make informed decision on my indexes. Sometimes the indexes SQL Server wants does not make sense to me. Does anyone know how I can figure out what wants it?
From what I understand the data will be "persisted" (physically stored, not just retrieved when i need it). Is this correct?
If so what would be the advantage of using an indexed view versus just using a table?
Whats query can be used to get the details of Indexes of any table? I need this to find out primarykey/autoincremented value of any table..
Please help/Guide me...
Does MySQL have an equalavent to MS SQL Servers "indexed view" functionality?
http://stackoverflow.com/questions/439056/is-a-view-faster-than-a-simple-query
What I'm specifically looking for is a way for MySQL to create a "view" that will return results faster than simply performing the underline view's query/sql.