Questions tagged [sql-optimization]

SQL Optimization refers to the process of testing and debugging SQL servers and queries in order to increase overall performance.

SQL Optimization refers to the process of testing and debugging SQL databases, servers and queries in order to increase the speed and performance and to reduce used resources.

Usually, SQL optimization can refer to:

  • SQL Query optimization, where the SQL queries are being optimized internally in order to be optimal and to use as little resources as possible.
  • Database (schema) optimization, where the database or schema itself is being optimized in order to minimize redundancy. In literature, this is also referred to as normalization.
  • SQL Server optimization, where server configuration is being modified in order to be optimal for the needs of the used application(s).
295 questions
0
votes
1 answer

Is it possible to optimize these queries any more?

Schema is like this visits_table: +---------------------------+----------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra …
Sebastian Piskorski
  • 4,026
  • 3
  • 23
  • 29
0
votes
2 answers

Query Optimization on SQL server 2008

I have a small sql query that runs on SQL Server 2008. It uses the following tables and their row counts: dbo.date_master - 245424 dbo.ers_hh_forecast_consumption - 436061472 dbo.ers_hh_forecast_file - 15105 dbo.ers_ed_supply_point - 8485 I am…
0
votes
2 answers

Export Data From Oracle to Excel - Performance issue

I am trying to create xls file using PL/SQL code via XML. I have referred : Create xls file using PL/SQL without going through xml generate XLS files using PL/SQL Code I have referred to can be found at :…
0
votes
2 answers

Conditional Aggregation with SUM and COUNT combined (different columns)

I have a table: State City Class Population S1 SC1 A 10 S1 SC2 B 5 S1 SC3 A 7 S2 S2C1 B 6 S2 S2C2 A 13 S2 S2C3…
0
votes
2 answers

Can I use aliases within a select statement?

I would like to write a statement that looks like this select 1 as one, 2 as two , one + two as three However SQL Server cannot work out what one + two is. I can re-write in this form SELECT x.one ,x.two ,x.one + x.two AS three FROM ( …
Loofer
  • 6,841
  • 9
  • 61
  • 102
0
votes
3 answers

Count without nested select: is this possible?

Database: Department Position Points A Manager 50 A Supervisor 10 A Supervisor 10 A Staff 2 A Staff 2 B …
0
votes
1 answer

How can I join these 25 INSERT queries into just one?

I have a web-based system that reads a sheet of an excel file (each sheet uploaded is 6 rows-5 columns) like this: Below is the code I'm using (for demonstration purposes I've set static values for the $entry but its real code would be for example…
0
votes
3 answers

How to use COUNT alias in SELECT?

I get an error for the below query: SELECT mt.tag_id, count(mt.tag_id) as bcount, bcount / t.count as rel, t.count as t FROM tags.media_tag as mt, tags.tags as t WHERE mt.media_id in (SELECT mt.media_id …
Zaheer
  • 2,794
  • 5
  • 28
  • 33
0
votes
1 answer

SQLite. How to optimize SELECT sub query?

entry table contains following columns: id, kanji, kana, meaning, compounds. This table has following DDL: CREATE TABLE entry ( id INTEGER PRIMARY KEY, kanji TEXT, kana TEXT, meaning TEXT, compounds BLOB); I want to update the column compounds.…
Joe Rakhimov
  • 4,713
  • 9
  • 51
  • 109
0
votes
0 answers

Calculate a View once

I've a problem of sql optimization I've a View, inside this View I must use another View, now the problem is that I must call this "inner view" more than one time, so this "inner view" is recalculated each time, is there a way to calculate it only…
davidinho
  • 169
  • 1
  • 14
0
votes
2 answers

inserting into a table with 3 million rows is slow

I have the following MySQL query: INSERT INTO shopious_instagram_item_viewer (created, viewer_id, item_id) VALUES ('2014-11-11 21:26:53', 210054, 714755)\G Here's how the table is structured: I am wondering why a simple insert like this would take…
adit
  • 32,574
  • 72
  • 229
  • 373
0
votes
1 answer

SQL General Optimization

recently was asked to help with query optimization The table looks like this: create table dbo.Table ( id int identity primary key clustered , column_1 varchar(64) not null , Date datetime not null , Column_2 varchar (32) not null , …
Andrey
  • 1,629
  • 13
  • 37
  • 65
0
votes
0 answers

How to optimize this sql queries?

I have 45 queries each one of them update a value in the table odds this value is taken from an array $odds_results for example $odds_results['1'] saved if the value of the column tahmin equals to 1 and so on Like this: $GLOBALS['db']->query("UPDATE…
0
votes
1 answer

Better performance SQL query

I am trying to check if there are better solution to this query question: Find the pairs of PC models having identical speeds and RAM. As a result, each resulting pair is shown only once, i.e. (i, j) but not (j, i). Result set: model with higher…
leo
  • 547
  • 6
  • 11
0
votes
5 answers

SQL Server sproc query optimization

I've got an application that generates data for reports that look like: age < 30 | age >=30 | asian | hispanic ----------------------------------------------------------------- clients in prog A | | …
rlb.usa
  • 14,942
  • 16
  • 80
  • 128