In SQL Server, there is the option to use query hints.
eg
SELECT c.ContactID
FROM Person.Contact c
WITH (INDEX(AK_Contact_rowguid))
I am in the process of getting rid of unused indexes and was wondering how I could go about determining if an index was used as a query hint. Does anyone have suggestions on how I could do this?
Cheers,
Joe
You can only run profiler for client SQL or search sys.sql_modules otherwise.
To find unused indexes you'd normally use something based on dmvs. This would show you what indexes are in use and need to be kept.
That's a great question, and I don't think I can give you an easy answer. If it were me, I would script th entire database in Management Studio and do a Text search for the index name. I would also do that in all of my reports and source code, just to be sure, too.
I don't think that hints make their way to sys.dependencies for procs an functions, but even if they did, you'd have some ad-hoc SQL to potentially deal with, so that's why I'd use the text searching route.
Related
I see this error in phpmyadmin:
The number of joins that do not use indexes
but I never use join in my code.
Now I want get a list of query that do not use indexes.
How can I get this list?
I tried enabling slow query log, but I can not understand which query is not use indexes.
Can someone guide me?
There is no list of "joins not using indexes".
Certain admin queries use VIEWs that have JOINs; possibly that is where they came from.
There are valid cases in which not using an index is OK for a JOIN. A simple example is joining two tables where one of the tables has so few rows that an index would not help with performance.
The slowlog provides something more important -- a list of the "worst" queries (from a performance point of view). Any "slow" query with JOIN that needs an index will show up, even without that setting turned on. (I prefer to turn off that option, since it clutters the slowlog with unexciting queries.)
I'll briefly mention that this isn't an error, it's not even really a warning. The Advisor tab is meant to make broad and generic performance suggestions that are meant to guide you towards optimizing your system. Having some of these suggestions that aren't fixable or don't apply to your situation is pretty normal. In fact, my test system gives the same advice about the join without an index.
As Rick James alluded to, these queries might not come directly from code that you write...some administrative tasks may be triggering it (your operating system might run some housekeeping queries, MySQL runs some queries against itself, etc).
The best way to look at the queries is to log them, which is answered in Log all queries in mysql. You could use the "Process" sub tab of the "Status" area in phpMyAdmin (very similar to how you get to the Advisor tab) to look at active queries, but that's not going to give you a complete picture over time. Once you have that list of queries, you can analyze them to determine if there are improvements you can make to the code.
I apologize in advance if I'm not doing this right, I'll try to follow all the rules but this is my first post on here.
The problem I'm having seems very simple.
I have a Microsoft Access 2007 database with a table that has approximately 300,000 records. I am attempting to query one of the fields in the table with a "Like" condition...
SELECT * FROM Table1 WHERE Field1 LIKE "*_TEST_*"
However, I'm finding this query has significant performance issues, taking 4-5 minutes to run compared to a few seconds if I take that particular "Like" criteria off. I've placed an index on [Field1] to try and alleviate the issue (and maybe I'm just a bit ignorant to the finer details of indexing) but it doesn't seem to have helped at all.
A colleague of mine informed me that these "Like" or "Contains" conditions would not see an improvement because of indexing, but did not really have any other ideas.
Could anyone please explain what it is about this "Like" criteria and indexing that don't play well together? And is there anything I can do to make this seemingly simple query work better?
Thanks so much!
Possibly related question: How could I generate a contextual text extract from text returned from a SQL Server Full-Text Index?
At any rate, I'd like to know if there is a way to get the position of the hit(s) within an indexed document. If this isn't possible, I was wondering if it's possible in any other full-text search technologies out there.
Thanks in advance!
EDIT: Derp. I just walked through the implications of the answer to that related question. If that's the best way then I guess it's the best way. Anyone have any better suggestions?
In the end sys.dm_fts_parser appears to be the best/only solution to this. Unfortunately it seems to be able to only handle a maximum amount of characters so it's on to Lucene.NET for me.
Other than running it to completion...
Is there some sort of progress you can monitor to see what operations are happening as your query is being processed that would give you a sense of how long it's going to take, or at least what step it is on, what steps have happened, and which remain?
If yes, would this same tool help you identify the part of your query that is taking the longest?
I'm trying to get a better sense for what makes some queries take longer than others.
It's called profiling : http://dev.mysql.com/tech-resources/articles/using-new-query-profiler.html
MySQL has one built-in for you. : )
You can use explain to ask MySQL to show you why a function takes as longs as it does.
http://dev.mysql.com/doc/refman/5.0/en/explain.html
The idea is that it'll show you things like which indexes it uses, etc, which will help you to then optimise either the query or the table to make it quicker.
That's not a direct answer to your question, because it won't tell you real-time progress of the query, which is what you're asking for, but it does directly answer the last sentence of your question, and so it may actually be more useful to you for what you really want to know than any real-time progress report would be.
i would like to return two record sets from a simple database table with one Linq2Sql query. I know how to do it if this was using Linq2Sql calling a stored procedure, but I don't want to use a stored procedure.
Is it possible to do it?
I've found an article here that has a suggested solution, but i hate the idea of having to write up a massive amount of code to partially extend the current context?! like... OUCH!!!
Just doesn't seem... right ?
Is the suggestion in the article the only way to do it? Are there other ways (without using stored procedures and still using Linq2Sql) ?
Wish Matt Warren was here to answer this :)
EDIT
I'm not asking about how to lazy-load / eager load (and using DataLoadOptions). That's a different concept.
Potentially you may do this with Multiple Active Result Sets (MARS) which I found from this page. It's an MSDN article on the topic, but does not specifically relate to LINQ to SQL, however this one does and probably the one you wanna check out.
Having said that, good luck because it looks like there's a bug posted to Microsoft regarding how it doesn't work, and the fix won't be here until .NET 4.0!
Lastly I understand you say you do not wish to use Stored Procedures, but if you do, I found a really simple guide here and here to get going.
That's the only way I've heard of it being done without a stored procedure. And you're right it does seem a bit excessive for a seemingly simple concept. If it was me I just get the records as separate result sets.