query-optimization

Optimizing a strange MySQL Query

偶尔善良 提交于 2019-12-13 07:30:07
问题 Hoping someone can help with this. I have a query that pulls data from a PHP application and turns it into a view for use in a Ruby on Rails application. The PHP app's table is an E-A-V style table, with the following business rules: Given fields: First Name, Last Name, Email Address, Phone Number and Mobile Phone Carrier: Each property has two custom fields defined: one being required, one being not required. Clients can use either one, and different clients use different ones based on their

Calculate backwards in a Javascript array

微笑、不失礼 提交于 2019-12-13 06:52:28
问题 Heres my currently working JsFiddle. I have 2 products 1 and 2 Then I have 3 STYLES for those products a user MUST select : s1,s2 and s3 Then I have table of prices that changes with the quantity and style people choose. See below This is my array. Quantity Quantity : [ 50, 100, 150, 200, 250] Product 1 prices for all 3 styles p1s1 : [2.00, 1.80, 1.60, 1.40, 1.20] p1s2 : [2.10, 2.00, 1.80, 1.60, 1.40] p1s3 : [2.25, 2.15, 2.05, 1.95, 1.75] Product 2 prices for all 3 styles p2s1 : [3.00, 2.80,

How do you optimize a MySQL query that joins on itself and does a “custom” group by?

半世苍凉 提交于 2019-12-13 06:09:09
问题 I have the following query that is starting to become slow as the size of the DB table increases: SELECT t.*, e.TranslatedValue AS EnglishValue FROM ( SELECT DISTINCT PropertyKey FROM Translations ) grouper JOIN Translations t ON t.TranslationId = ( SELECT TranslationId FROM Translations gt WHERE gt.PropertyKey = grouper.PropertyKey AND gt.Locale = 'es' AND gt.Priority = 3 ORDER BY gt.ModifiedDate DESC LIMIT 1 ) INNER JOIN Translations e ON t.EnglishTranslationId = e.TranslationId ORDER BY t

DB Design and Data Retrieval from a heavy table

孤街浪徒 提交于 2019-12-13 06:07:49
问题 I have a requirement to have 612 columns in my database table. The # of columns as per data type are: BigInt – 150 (PositionCol1, PositionCol2…………PositionCol150) Int - 5 SmallInt – 5 Date – 150 (SourceDateCol1, SourceDate2,………….SourceDate150) DateTime – 2 Varchar(2000) – 150 (FormulaCol1, FormulaCol2………………FormulaCol150) Bit – 150 (IsActive1, IsActive2,……………….IsActive150) When user does the import for first time the data gets stored in PositionCol1, SourceDateCol1, FormulaCol1, IsActiveCol1,

Is it possible to replace NL join with HS join in sql

白昼怎懂夜的黑 提交于 2019-12-13 05:29:37
问题 Hi am having a very big query comprises of two main table and 15 sub tables. ie, Main table say table_a join with some other 10 tables. and another main table sat table_b join with some other 5 tables. Table_a contains - 314988 rows and Table_b contains - 710989 rows. when we join i could find many NL Joins and HS joins. intresting fact that all HSjoin cost very less and NL join cost very very high. So is it possible to convert the joins from NL to HS Join. Note : its all indexed.. there is

Need help with optimizing a SQL query

让人想犯罪 __ 提交于 2019-12-13 05:19:56
问题 I desperately need help with a query that's been causing a lot of grief over the past 6 months on a high traffic website. I am a frontend developer with ability to write simple SQL queries and so I am unable to fix this issue on my own. The query is now locking mysql database frequently for lack of memory or CPU or interference from other queries on the VPS. I upgraded the hardware, but that alone didn't resolve the issue. So here's a description of what the query is trying to do: User

Trouble optimizing MySQL query

大城市里の小女人 提交于 2019-12-13 03:44:36
问题 I'm working on the following query but not sure how to proceed with further optimizations: SELECT u.id AS userId, firstName, profilePhotoId, preferredActivityId, preferredSubActivityId, availabilityType, 3959 * ACOS(COS(radians(requestingUserLat)) * COS(radians(u.latitude)) * COS(radians(u.longitude) - radians(requestingUserLon)) + SIN(radians(requestingUserLat)) * SIN(radians(u.latitude))) AS distanceInMiles FROM users u WHERE u.id IN ( SELECT uu.id FROM users uu WHERE uu.latitude between

Optimizing query to get entire row where one field is the maximum for a group

一笑奈何 提交于 2019-12-13 03:23:58
问题 I have a table with a schema like, say, EventTime DATETIME(6), EventType VARCHAR(20), Number1 INT, Number2 INT, Number3 INT, ... There are an unimaginably large number of rows in this table, but for the sake of this query I'm only interested in, say, a few thousand of them that are between two given values of EventTime . There's an index on EventTime , and if I just do something like SELECT * FROM table WHERE EventTime >= time1 and EventTime <= time2; Then it's able to return the relevant

Oracle query performance with BETWEEN operator

让人想犯罪 __ 提交于 2019-12-13 03:00:01
问题 I have a table with about 100million rows. Have to use BETWEEN operator. I see that query is running very slow. I added 2 indexes on trader table one on t.name and second index is t.amount and t.price. Query is performing very slow. Does indexing on price and amount help when using BETWEEN operator. Also, how can I optimize this? select t.trader_id, t.name, t.city, t.state from trader t where exists ( SELECT null FROM city_present p,city_state c WHERE p.name = 'TEST_TEST' AND c.city = p.city

Queries within queries: Is there a better way?

被刻印的时光 ゝ 提交于 2019-12-13 02:26:27
问题 As I build bigger, more advanced web applications, I'm finding myself writing extremely long and complex queries. I tend to write queries within queries a lot because I feel making one call to the database from PHP is better than making several and correlating the data. However, anyone who knows anything about SQL knows about JOIN s. Personally, I've used a JOIN or two before, but quickly stopped when I discovered using subqueries because it felt easier and quicker for me to write and