query-optimization

Web page database query optimization

大兔子大兔子 提交于 2019-12-14 02:28:59
问题 I am putting together a web page which is quite 'expensive' in terms of database hits. I don't want to start optimizing at this stage - though with me trying to hit a deadline, I may end up not optimizing at all. Currently the page requires 18 (that's right eighteen) hits to the db. I am already using joins, and some of the queries are UNIONed to minimize the trips to the db. My local dev machine can handle this (page is not slow) however, I feel if I release this into the wild, the number of

sql server procedure optimization

别来无恙 提交于 2019-12-13 20:12:32
问题 SQl Server 2005: Option: 1 CREATE TABLE #test (customerid, orderdate, field1 INT, field2 INT, field3 INT) CREATE UNIQUE CLUSTERED INDEX Idx1 ON #test(customerid) CREATE INDEX Idx2 ON #test(field1 DESC) CREATE INDEX Idx3 ON #test(field2 DESC) CREATE INDEX Idx4 ON #test(field3 DESC) INSERT INTO #test (customerid, orderdate, field1 INT, field2 INT, field3 INT) SELECT customerid, orderdate, field1, field2, field3 FROM ATABLERETURNING4000000ROWS compared to Option: 2 CREATE TABLE #test (customerid

is my large mysql table destined for failure?

戏子无情 提交于 2019-12-13 19:17:09
问题 I have built a mysql table on my local computer to store stock market data. The table name is minute_data , and the structure is simple enough: You can see that I made the key column a combination of date and symbol -> concat(date,symbol) . This way I do an insert ignore ... query to add data to the table without duplicating a date/symbol combination. With this table, data retrieval is very simple. Say I wanted to get all the data for the symbol CSCO , then I could simply do this query:

Why is the index on s not used for sort here?

倖福魔咒の 提交于 2019-12-13 15:01:46
问题 Setup: mysql> create table test(id integer unsigned,s varchar(30)); Query OK, 0 rows affected (0.05 sec) mysql> insert into test(id,s) value(1,'s'); Query OK, 1 row affected (0.00 sec) mysql> insert into test(id,s) value(1,'tsr'); Query OK, 1 row affected (0.00 sec) mysql> insert into test(id,s) value(1,'ts3r'); Query OK, 1 row affected (0.00 sec) mysql> create index i_test_id on test(id); Query OK, 3 rows affected (0.08 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> create index i_test_s

How to optimize retrieval of most occurring values (hundreds of millions of rows)

混江龙づ霸主 提交于 2019-12-13 14:40:22
问题 I'm trying to retrieve some most occurring values from a SQLite table containing a few hundreds of millions of rows. The query so far may look like this: SELECT value, COUNT(value) AS count FROM table GROUP BY value ORDER BY count DESC LIMIT 10 There is a index on the value field. However, with the ORDER BY clause, the query takes so much time I've never seen the end of it. What could be done to drastically improve such queries on such big amount of data? I tried to add a HAVING clause (e.g:

Why is this query using where instead of index?

試著忘記壹切 提交于 2019-12-13 13:19:01
问题 EXPLAIN EXTENDED SELECT `board` . * FROM `board` WHERE `board`.`category_id` = '5' AND `board`.`board_id` = '0' AND `board`.`display` = '1' ORDER BY `board`.`order` ASC The output of the above query is id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE board ref category_id_2 category_id_2 9 const,const,const 4 100.00 Using where I'm a little confused by this because I have an index that contains the columns that I'm using in the same order they're used in

Using GORM efficiently to retrieve join data - Grails 2.3

寵の児 提交于 2019-12-13 12:50:52
问题 I have User, and Follow Domain class that construct the Follower, Following relationship like Twitter. When my User visits another User's page, and click on their Follower list. I pop-up the list of the visited person's follower list, and then show a button in front of it that is labeled "Follow" or "Unfollow" depending on if you already following that person. So I do it the following way, but I'm not sure if this is efficient or maybe there is a better way of doing it. In order to make it

Composite primary keys in N-M relation or not?

泪湿孤枕 提交于 2019-12-13 12:37:16
问题 Lets say we have 3 tables (actually I have 2 at the moment, but this example might illustrate the thought better): [Person] ID: int, primary key Name: nvarchar(xx) [Group] ID: int, primary key Name: nvarchar(xx) [Role] ID: int, primary key Name: nvarchar(xx) [PersonGroupRole] Person_ID: int, PRIMARY COMPOSITE OR NOT? Group_ID: int, PRIMARY COMPOSITE OR NOT? Role_ID: int, PRIMARY COMPOSITE OR NOT? Should any of the 3 ID's in the relation PersonGroupRole be marked as PRIMARY key or should they

Are execution times of these SQL queries the same?

放肆的年华 提交于 2019-12-13 09:36:46
问题 I believe the result obtained by these 2 queries is the same? The first query: SELECT sensor_id, measurement_time, measurement_value FROM public.measurement_pm2_5 WHERE (sensor_id = 12 AND measurement_time BETWEEN to_timestamp(3000) AND to_timestamp(12000)) OR (sensor_id = 27 AND measurement_time BETWEEN to_timestamp(3000) AND to_timestamp(12000)) OR (sensor_id = 1 AND measurement_time BETWEEN to_timestamp(500) AND to_timestamp(1000)) OR (sensor_id = 1 AND measurement_time BETWEEN to

How to use left outer join in mysql to get my desirable results?

妖精的绣舞 提交于 2019-12-13 07:38:51
问题 I have made an sql fiddle. Users with id 100 and 118 should have 0 records for assigned_scopes , assigned_qa , failed_qa and assigned_canvass . But it does not display that data; it just shows the record for the user with id 210 . What I really need is to display all the users, with 0 in each column if they have nothing. How can I do this? What I have tried since is in this fiddle. It works according to my requirements but there is problem with query optimization; its execution time is not