query-optimization

How do I display execution time of a MySQL query in PHP?

人走茶凉 提交于 2020-01-04 03:00:48
问题 I am working on a PHP application that takes queries in a text box and returns paginated results. As part of the application I want to report the running time of the query. Here is what I have done so far. I started off by enabling profiling in by directly entering in the text box and running the script: set global profiling = 1 Using the provided text box I enter the following query: select @@profiling And get: 1 Finally, I run the query as so: select * from log However, when I run the

Hive Tez reducers are running super slow

风格不统一 提交于 2020-01-04 02:29:13
问题 I have joined multiple tables and the total no of rows are around 25 billion. On top of that, I am doing aggregation. Here are my hive settings as below, which I am using to generate the final output. I am not really sure how to tune the query and make it run faster. Currently, I am doing trial and error and see if that can produce some results but that doesn't seem to be working.Mappers are running faster but reducers are taking forever to finish off. Could anyone share your thoughts on this

How can I use COALESCE() in WHERE clause optimally?

倾然丶 夕夏残阳落幕 提交于 2020-01-03 18:42:09
问题 Here is my query: select coalesce(qa2.subject, qa.subject) as question_subject, qa.body, (select count(*) from viewed_items vi where coalesce(qa.related, qa.id) = vi.question_id ) as total_question_viewed from questions_and_answers qa left join questions_and_answers qa2 on qa.related = qa.id where body like ':entry'; As you know, MySQL optimizer can never use a index on this on coalesce(qa.related, qa.id) = vi.question_id . So any idea how can I write this query more optimal? 回答1: You can do

Fetch only N rows at a time (MySQL)

*爱你&永不变心* 提交于 2020-01-03 17:12:22
问题 I'm looking for a way to fetch all data from a huge table in smaller chunks. Please advise. 回答1: To answer a question from the title use LIMIT operator SELECT * FROM table LIMIT 0,20 as for one from body, it's too broad to ask for a certain code example, doesn't it? 来源: https://stackoverflow.com/questions/3599548/fetch-only-n-rows-at-a-time-mysql

SQL Server 05, which is optimal, LIKE %<term>% or CONTAINS() for searching large column

那年仲夏 提交于 2020-01-03 17:05:42
问题 I've got a function written by another developer which I am trying to modify for a slightly different use. It is used by a SP to check if a certain phrase exists in a text document stored in the DB, and returns 1 if the value is found or 0 if its not. This is the query: SELECT @mres=1 from documents where id=@DocumentID and contains(text, @search_term) The document contains mostly XML, and the search_term is a GUID formatted as an nvarchar(40). This seems to run quite slowly to me (taking 5-6

MySQL: Optimization GROUP BY multiple keys

旧时模样 提交于 2020-01-02 10:26:13
问题 I have a table PAYMENTS in MySql database: CREATE TABLE `PAYMENTS` ( `ID` BIGINT(20) NOT NULL AUTO_INCREMENT, `USER_ID` BIGINT(20) NOT NULL, `CATEGORY_ID` BIGINT(20) NOT NULL, `AMOUNT` DOUBLE NULL DEFAULT NULL, PRIMARY KEY (`ID`), INDEX `PAYMENT_INDEX1` (`USER_ID`), INDEX `PAYMENT_INDEX2` (`CATEGORY_ID`), INDEX `PAYMENT_INDEX3` (`CATEGORY_ID`, `USER_ID`) ) ENGINE=InnoDB; I want to get summary amount for each user in ech category. Here is script: select sum(AMOUNT), USER_ID, CATEGORY_ID from

Improve MySQL Query with IN Subquery

你离开我真会死。 提交于 2020-01-02 05:23:11
问题 I hava a table items and a table item_attributes . For simplicity let's say my table item has a column id and a column name . Of cource there is a index on the id column. the item_attributes table has the columns id , item_id , attribute_name and attribute_value and an index ON attrubute_name Now I want to query all items with a specific attribut without using a join. I do this with the following query: SELECT * FROM items i WHERE i.id IN ( SELECT item_id FROM item_attributes a WHERE a

Group by and group concat , optimization mysql query without using main pk

孤者浪人 提交于 2020-01-02 03:52:04
问题 my example is on MYSQL VERSION is 5.6.34-log Problem summary the below query takes 40 seconds , ORDER_ITEM table has 758423 records And PAYMENT table has 177272 records And submission_entry table has 2165698 records as A Whole Table count. DETAILS HERE: BELOW: I Have This Query, Refer to [1] I Have added SQL_NO_CACHE for testing repeated tests when re query. I Have Optimized indexes Refer to [2] , but no significant improvement. Find Table Structures here [3] Find explain plan used [4] [1]

How to optimize a query with multiple OR, AND, IN statements?

你。 提交于 2020-01-01 22:06:28
问题 I have a an SQL query as below: Declare @ConnectionType int = 5, @UserId int = 2 select * from CallDetails Where ((@ConnectionType = 0 AND CallDetails.DeviceType IN (0,1,2,3,4,5,7,8)) OR (@ConnectionType = 1 AND CallDetails.DeviceType = 4) OR (@ConnectionType = 2 AND CallDetails.DeviceType IN (0,1,2,3,7)) OR (@ConnectionType = 3 AND CallDetails.DeviceType = 5) OR (@ConnectionType = 4 AND CallDetails.DeviceType IN (0,1,2,3,4,7)) OR (@ConnectionType = 5 AND CallDetails.DeviceType IN (4,5)) OR (

SQL Optimization in Oracle

别来无恙 提交于 2020-01-01 11:53:31
问题 We are using Oracle 11 and I recently acquired a Dell SQL Optimizer (included with the Xpert Toad package). We had a statement this morning that was taking longer than normal to run, and after we eventually got it running (missing some conditions from when it was created) I was curious, having never used any SQL optimizer before, what it would change it to. It came back with over 150 variations of the same statement, but the one with the lowest cost simply added to the following line. AND o