Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    MYSQL


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Slow View Queries


I have a fairly complex view which, when you execute a SELECT * shows all info very quickly (0.24 seconds to return nearly 3000 rows). However, when I start throwing slightly more complex queries at it, things really slow down - an average query can take 40 seconds to execute.




View Complete Forum Thread with Replies

Related Forum Messages:
Slow Queries When Using Views Compare To Direct Table Queries
I’ve having problems with my server load for a while now. I have two tables with different content, but I need to display them in the same results, so I created a view with a union all (named: top_news_videos). The problem that I’m seeing is that when running a select to the view it takes a lot longer (and in that way, more server intensive) than running the query directly to one of the tables. For example, I created a page where I run 7 queries similar to this one:

MySQL Code: ...

View Replies !
View Slow Query Log
I searched here, google and MySQL docs but did not find an answer.
I'm using MySQL-Front from a Windows platform to administer a remote database. The remote server doesn't have phpMyAdmin or anything like that.
MySQL-Front reports 133 Slow Queries and an average of 15 queries per second. But I dont' know how get more information than that.

View Replies !
Way To View Recent Queries
Is there a way to view recent queries running on Mysql server (say last 3 minutes). In our application we faced, lock wait time out issue. I suspect some of the queries executed causes this issue.. If I check the queries that running on Mysql server, that may give a clue or may help to identify the issue.

View Replies !
Too Slow Queries
I am using version 5.0.4. I noticed that suddenly my queries were becoming too slow. I have data in three tables, with 40,000 rows, 50,000 rows and 70,000 rows respectively. I was able to run queries that joined the three tables together and get the results in less than 5 seconds. I tried updating the tables through a program that used a stored procedure to delete the tables but I had some other problems. Since the I restored the data in the tables from backup databases. Now I can't run any queries that join the three tables together, it waits for a long time and then times out. The data in the tables look good. Now I can't get the results from any of the other backup databases either. It look like the entire MySQL server has slowed down greatly. I tried rebooting the server to no avail.

View Replies !
Slow Queries!
I have a website which has a users table in a mySQL database. This users table is large (It has about 25 columns - most varchar(100)) but only has about 10000 records. The records contain user information which is searched with a javascript form.
My problem is that when I click to 'view all', it takes about 7 seconds to load. This seems a lot?
Does 25 cloums seem sxcessive in a table? Can anyone point me to some good tutorials / docs on improving query performance? I have defined the colums as best as I can, but I am using SELECT * from table, would selecting individual columns make a big difference?

View Replies !
What Causes Slow Queries
What causes periodic slow queries? I have checked my slow query logs and for some reason everyonce in awhile, a query thats never slow might be for example, one took 3 seconds to execute and every once in awhile a chat might take 10 seconds of cpu time while rest of the time 0.09...why is it it flexuates so much?

View Replies !
How To Log-slow-queries
I'm running MySQL 5.0.

Now I would like to log-slow-queries. With MySQL 4 I used

mysqld --log-slow-queries --log-long-format start

but now I get following note:

mysqld: Too many arguments (first extra is 'start').
Use --help to get a list of available options

It looks like starting and stopping now only works with

etc/init.d/mysql start

View Replies !
Slow Queries And Optimization
I am hosting a site with an increasing number of members. Letely the site has become slower because of too many queries are being used.
Is there a way of asking the server which queries are used most often, as well as asking which queries take a long time to process so that I would know where to start my optimization process?

View Replies !
Enabling -- Log - Slow - Queries
I want to enable --log-slow-queries of MySQL.

How do I do it without restarting the DB server?

View Replies !
Slow Queries With LIMIT
Working with a large table (1 Million Records). Setting up pagination using LIMIT command.

Queries near the end of the table are slow when non-indexed fields are selected (but not included in the 'where' clause).

For example:

With indexes on id (PK), and type:

SELECT id, user_id, name, type, selected, creation_date FROM titans where type = 2 LIMIT 500010,10;
+---------+---------+------------+------+----------+---------------+
| id | user_id | name | type | selected | creation_date |
+---------+---------+------------+------+----------+---------------+
| 1000016 | 100001 | Uni Ekko | 2 | 0 | 1228149051 |
| 1000017 | 100001 | Dynaneedle | 2 | 0 | 1228149074 |
+---------+---------+------------+------+----------+---------------+
2 rows in set (4.17 sec)

If I only search on the ID field, the query is much faster.

mysql> SELECT id FROM titans where type = 2 LIMIT 500010,10; +---------+
| id |
+---------+
| 1000016 |
| 1000017 |
+---------+
2 rows in set (0.36 sec)

explain SELECT id, user_id, name, type, selected, creation_date FROM titans where type = 2 LIMIT 500010,10;
+----+-------------+--------+------+-------------------+---------------+---------+-------+--------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+------+-------------------+---------------+---------+-------+--------+-------------+
| 1 | SIMPLE | titans | ref | avatars_indx2,tst | avatars_indx2 | 2 | const | 381988 | Using where |
+----+-------------+--------+------+-------------------+---------------+---------+-------+--------+-------------+
1 row in set (0.01 sec)

View Replies !
Unable To See Queries In MySQL In Database View Dreamweaver...
I have MySql running on my Mac using NaviCat, I have created a few tables and a Query, When I load Dreamweaver I can see the Tables but can not see the Query. Would anyone be able to help me with this?

View Replies !
Do Unnecessary Parentheses Slow Queries Down?
I know a person who seriously writes queries like this:

SELECT * FROM my_table WHERE ((((my_col = 30))) AND (((other_col = 40))))

I told him all those parenthesis were unnecessary and he responded that he does it so later if he has to add more criteria the parenthesis will be there. I about fell out of my chair that sounds so ridiculous. So my question is, other than the obvious ugliness and being hard to read, is there any other reasons why NOT to do this?

View Replies !
Optimizing Slow Queries On Millions Of Records
I have a table that has millions of records in it.
About 100 records are added every 5 minutes (one per OIDID) (the sample
provided below has data for 2 OIDIDs (99 and 100)
And I have a webpage that executes 9 queries one after the other, and then
displays the results on the webpage.

When the database was empty, this process was very quick.
But, as the DB grew, it became slower.
Now it takes about 38 seconds for all queries in the example below.
MySQL 4.1 on Windows

I have tried different indexes, and they do help and are used, but the
queries still seem to take a long time. Code:

View Replies !
Fine Tune :: Timeout Slow Queries?
I have a very busy database with some tables having hundreds of thousands of records. I am running MySQL 5.0.16 on Windows. Some of the queries running on my database are not fined-tuned enough, and need improvement. However, the system is live in production and I am looking for a way to prevent MYSQL from committing Harakiri, i.e. from running very slow queries forever, taking the cpu to 50% and beyond for hours. My scripting language is PHP. I found that after a while the end user receives a timeout on the browser, but MySQL continues trying to run the query, sometimes for hours.

My question is, is there a way to specify a timeout for MySQL so that it will abort any queries that it is running that have not returned a result by then. The end user is no longer around anyway, so I am looking for a way to protect the database resources (and in parallel I will start investigating how to optimize the slow queries)

View Replies !
MySQL Timing Out? Really Slow Queries, Already Indexed.
For whatever reason, MySQL does not seem to be executing. So, I ran a few stat functions and here is what I got:

Uptime: 220372
Threads: 39
Questions: 18748899
Slow queries: 808
Opens: 28723
Flush tables: 1
Open tables: 4096
Queries per second avg: 85.078

The "open tables" worries me for a few reasons. First, because it is 4kb (exactly, since it is divisible by 1024, evenly). This makes me think that maybe I am hitting a ceiling.

Second, there are a few variables in MySQL that equal this, and maybe it's a cap on something. Here are the variables that equal 4096:
query_cache_min_res_unit = 4096
table_cache = 4096
transaction_prealloc_size = 4096

Do any of those have anything to do with this? Am I even close? Are any of those values from mysql_stat a big deal?

View Replies !
Slow Queries, 4 Million Records, Need Educated Advice!
I have created an app a few years back to store some records in a DB.
According our calculations we were never to exceed 500,000 records in
the DB. Seems we were off by a decimal point or so.

I set up a FreeBSD box with MySQL three years back and it has been
filling up. One table has over 4,000,000 records. Yes, four million.

As a web developer and not a DBA, I have struggled to upkeep the server
the best I can. As of the last one million records the server has been
struggling to keep up with multiple requests and as you can imagine the
user base is growing too.

Hardware:
Dual Xeon 3.06 Ghz
4 GB ECC RAM
800GB RAID5 SATA array

Software:
FreeBSD 5.3
Apache 2.0
PHP5
MySQL 5.0.2

Basically I have to perform a search on one of two columns in this huge
table (10 columns, 4 million rows).

The table is MyISAM with a single primary key that is used largely for
updating row data.

Most records are ten digit numbers for one column and a ten digit
varchar for the other, but sometimes either column can be a series of
characters up to 100 chars long, so each column is set for
varchar(100).

The action performed is

SELECT count(*) FROM tableName WHERE col LIKE "%123%"

then...

SELECT * FROM tableName WHERE col LIKE "%123%" LIMIT 0,25

with "%123%" being any random string typed into a search window.

View Replies !
Join On A View Without The View
I was wondering what the syntax would be to have a left join from one table to a resulting query without the view. Currently I use a view and it works fine but I was wondering how to achieve this without creating the view.

Here is the current view's SQL statement ( without the create view etc)...

View Replies !
Complex Queries Versus Multiple Simple Queries
I am constructing a database to contain information about stories posted on my site. Information included will be things like title, author(s), genre(s), story codes, synopsis, etc.

I worked out that storing this information properly, so that it can all be searched on, could take as many as ten tables.

My question is this: Is a single complex query really better (more efficient for the server) than multiple simple queries? In other words, I may need the information for as many as 25 or even 50 stories for a single page.

Is it better to get all of the information out of a single, massive, complex query, or is it acceptable to get the information essentially one story at a time, which could mean 25 or 50 simple queries...?

View Replies !
Many Smaller Queries Vs. Large Comlicated Queries
I am wondering if any one can help me. I have a page that will run around 85 smaller queries but if i combine the queries it will go down by almost half. This page is a high traffic page and I don't a complicated query taking up mysql resources while it created a temp table and such. My question is this:

Is it better for mysql to run a lot of smaller queries (ex: simple selects with zero or one join, group by) or one larger complicated query with everything combined.

The thing i have to keep in mind is that the mysql selects are comming off the localhost that the web server is also running on so they share the same resources.


View Replies !
Long Queries VS Multiple Short Queries
I have a php script that requests a very long query from our mysql database. It has lots of joins and accesses at least 5-6 tables. My question is should i break it up into smaller separate queries or leave it as one long one, in regards to best practices?

View Replies !
Using A View
I want to use a view but I'm unsure how exactly MySQL handles a view and I can't seem to find anything about it in the docs. I guess my question is:

Is a view stored as a physical table or is it stored in memory or what? I'm asking because I want to make sure that if it is stored in memory that the amount of ram on my db server doesn't become an issue.

View Replies !
What Is A VIEW?
What is a VIEW?

Why when I go to chapter 23 does it tell me how to create, alter, and drop a view, but it doesn't say what it is or what they're used for? Maybe I missed it, but is there any place in the reference where a sentence starts, "A VIEW is...".

The closest I've come (looking outside of MySQL site) is a view is 'a predefined join of specified tables'.

I take that to mean it is essentially a shortcut to a specific data set relationship and based on that I can see how it is useful, but why isn't this concept defined in the manual? Is it really so obvious that it doesn't require any explanation, or god forbid a demonstration of how it is used?

Even more evidence that this is a stupid question is that when I google 'what is a mysql view' I get bounced back to the reference.

View Replies !
Is This Possible With A View?
I'm trying to cut down on the size of my database so I've changed it so that rather than implicitly setting every value in one table, I've split the data into two tables: one table (iData) contains data for the start of evey week:
iData
-----------------------------
2000-01-01 Volume: 20000000
2000-01-06 Volume: 30000000
2000-01-11 Volume: 40000000
Another table (jData) contains the delta (difference) from the previous iData entry:
jData
-----------------------------
2000-01-02 Volume: 1
2000-01-03 Volume: -2
2000-01-04 Volume: 1
2000-01-05 Volume: 3
2000-01-07 Volume: 2
2000-01-08 Volume: -5
2000-01-09 Volume: 6
2000-01-10 Volume: 1
2000-01-12 Volume: 2
2000-01-13 Volume: -4
2000-01-14 Volume: 4
2000-01-15 Volume: 3

Obviously this will save a lot of space as the delta is much smaller than storing the exact value (standard compression technique).

So what I would like to do is create a view to automatically display all of the data as if it were all stored in one table:

All Data:
---------
2000-01-01 Volume: 20000000
2000-01-02 Volume: 20000001
2000-01-03 Volume: 19999999
2000-01-04 Volume: 20000000
2000-01-05 Volume: 20000003
2000-01-06 Volume: 30000000
2000-01-07 Volume: 30000002
2000-01-08 Volume: 29999997
2000-01-09 Volume: 30000003
2000-01-10 Volume: 30000004
2000-01-11 Volume: 40000000
2000-01-12 Volume: 40000002
2000-01-13 Volume: 39999998
2000-01-14 Volume: 40000002
2000-01-15 Volume: 40000005

I know I can do this programatically, but is it possible to do this with a view? Any pointers would be much appreciated.



View Replies !
View With Parameters
can I put parameters into a view?

example

CREATE VIEW `dmz_sms`.`vwProva` AS
SELECT * FROM tb_sms where id=@ID;

I get error 1351.

View Replies !
View Schema
is there a tool to view a schematic of a MySQL DB I don't mean the .sql file I mean a pretty chart type schematic.

View Replies !
VIEW In MySQL
select NO_RESPONSABLE, NOM + PRENOM as NAME from RESPONSABLE

Gives me the number of the ID, but also "0" as the result of the
concatenated NAME.

View Replies !
Mysqldump View
I try to dump the view definition and records using the following command.

mysqldump -uroot -psecret! --databases test --tables proxy_view > mytest.txt

What all I get is the view definition without records. What is the correct method of dumping a view?

View Replies !
View Dependencies
When creating a view, it will (almost certainly) take information from one or more existing tables/views in the database. If I come to the database with no knowledge about the view (other than its name), how can I determine which underlying tables it depends on?

(I can do this is PostgreSQL by performing queries against the pg_class & pg_depends internal tables but I haven't discovered any way of doing it in MySQL either with SQL queries or with the C API.

View Replies !
Exponential View
how to store numbers in exponential view to MySQL. E.g. 4,56e-9 = 0,00000000456

I have 4,56e-9 as a variable in perl and want to store it to MySQL. Decimal as typ seems not to work. Does i realy have to convert it to 0,00000000456?

View Replies !
VIEW Problem
I create the next view:

CREATE VIEW VideoDB.FindCustomer AS
SELECT id, last_name&' '&name&' '&initial AS cname, picture, birthday, birthday_already, account_type, rents, exp_date, deposit, exp_deposit, auto1, kinship1, auto2, kinship2,
auto3, kinship3, auto4, kinship4, auto5, kinship5, auto6, kinship6
FROM VideoDB.customers;

When I execute the next statement the result is 0:
select cname from videodb.findcustomer;

How can I concat the whole name.
last_name&' '&name&' '&initial AS cname

View Replies !
View Foreign Key
My problem is that after creating a foreign key, I cannot see in MySQL/phpMyAdmin that a column is a foreign key, here is an example of 2 tables (I wanted to create a table with users in a community an create a table=relationship which contains the information about which users know each other):

CREATE TABLE `user` (
`id` double NOT NULL auto_increment,
`security_code` varchar(50) NOT NULL,
`active` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
);

CREATE TABLE `knows` (
`user_id_1` double NOT NULL,
`user_id_2` double NOT NULL,
KEY `benutzer_id_1` (`benutzer_id_1`),
KEY `benutzer_id_2` (`benutzer_id_2`)
);

Now ... after creating (using the ALTER command of MySQL) two foreign keys (linking 'knows' with 'user') in the 'knows' database (which are of course 'user_id_1' and 'user_id_2') I cannot see any changes on my tables in phpMyAdmin. Why? After using the export function of phpMyAdmin, there is nothing about the foreign keys in the generated SQL. Why?
And another question concerning the relationship 'knows', would you give me some idea about how to create it in DBDesigner 4 or Workbench? There is something that I do not understand:
In school we learned a lot about ERM. And in ERM you were able to define attributes for relationships (for example 'date' for table 'knows', which would inform me about when we have added the info). In DBDesigner a relationship can only be made as a connection between Entities, but without any attributes. And how would I define such recursive relationship like 'knows' (from above) in DBDesigner 4 then, so that the tool would add to the relationships foreign keys automatically and export the relationship 'knows' as a table later on?

View Replies !
SQL Source For A View
How do you obtain the SQL source that created a View?

I can Describe the view, but that doesn't give me the SQL that created it.

. . .

I should have searched the forums a little longer. The answer lies in the

SHOW CREATE VIEW viewName statement.

View Replies !
If Condition In View
Basically i want to add put a where condition in a view if the user variable '@org_id' is > 0. Here is some pseudo code:

CREATE VIEW view_students AS
SELECT *
FROM students
If (@org_id > 0) THEN
WHERE org_id = @org_id
END IF

I've tried lots of different approaches but i just cant figure out how to do it.

View Replies !
View Optimization
In my database I have separate four tables and from that four tables i have created one view. Each of the table contains round five lacs of records. So when view gives result it is approximately around fifteen lacs of records,

When I call that view like "select * from MyView where name='vimal'" it takes too long to give me result. And due to this one query my application server load increases by 80%. When I execute this view that time mysql Memory consumption is approximately 80% of total memory. What I can do to optimize the same? What are the other alternatives?

View Replies !
Can't View Tables
I have a table located in the following directory. C:ProgramFilesMysqlDataRecipesTablesshirt.sql
The Database is Recipes and within that Database is another Database called Tables that has several tables I just used the shirt table as an example. How do I get to this table?

View Replies !
Create A View
I have a master table and five detail tables. Now I want to have an overwiew on all detail tables that are related to the master table. The problem is that there are to many repeated records.

My wish is that to have each record of detail table in a single row with master table information in the view table. I tried to reach this with joins (left or right). No chance.. Code:

View Replies !
(View) Performance
I have a huge table with product data from different shops in my database. There is a flag column 'import' witch flagt products with 1 for my PHP script.

To select from one shop all product individually, work with it, and then update these product import flag to 0 in the database, seems to be the slowest way. I thougt about a view about all products of a shop with flag '1'. Code:

View Replies !
Creating A VIEW Using Php
$query="CREATE VIEW test AS SELECT option_price.option_id,plan_id,name FROM option_name,option_price WHERE (option_name.option_id = option_price.option_id) ORDER by option_name.option_id ";
$results = mysql_query($query);

View Replies !
Can't Create View
I am using MySQL 5.0.0 server Alpha release. Though the manual suggests that views on tables can be created in this version but i am unable to do so.

I have a table named 'ads'.
I am creating a view named 'test' with following syntax..
create view Test as select * from ads;

Msg returned by MySql is:
[MySQL] ERROR 1064: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'view Test as select * from ads' at line 1.

View Replies !
Auto_Increment In A View
I have a table that is in no particular order, I would like to organize it in a view by ordering it and creating a new auto_increment field. Is this possible?

I used to just create a new ordered table and then alter it with a auto_increment field but that takes too much time.

Is there any other better solution to this?

View Replies !
Create View
I currently have a script that I have developed on a MS SQL server. As part of it I use a VIEW to do most of my lookups. I want to transfer it to a MYSql DB, but when I try and CREATE VIEW I get the following message....


mysql> create table t (qty INT, price INT);
mysal> insert into t values (3, 50);
mysql> create view v as select qty from t;
ERROR 1064: You have an error in your SQL syntax. Check the manual that corresp
onds to your MySQL server version for the right syntax to use near 'view testv a
s select qty from t' at line 1
mysql>

I am using MYSQL for Netware. I am using an example that I have found to demostrate it, but it just does not work.

View Replies !
UPDATEABLE VIEW
I am getting an error when updating a table from a view in MySQL 5.
I have created a view & then reference it in my update command, by MySQL caomes back with an unknown table error.

I can 'show' & 'describe' the view, so it is definately there.

View Replies !
How To View All The Sp Created?
is there a way to view all the stored procedure created in mysql? a command to view all avaialble sp's?

View Replies !
Currency View
When displaying product prices in MySQL database its only showing 17.5 instead of 17.50. Tried different things in Excel to make the view display correctly, but had no luck. Any ideas?????

View Replies !
View The TimeStamp
I know you can view when a table was updated in mySQL Administrator. Is there a way in SQL to view that TimeStamp?

View Replies !
View SQL Files
I am about to by the content of a site, but it is in sql files. I need to view this content and extract to make a new site from it in html format.

How do I view SQL files and extract it content? Is there any program that does it?

View Replies !
Can I View .frm, .MYD And .MYI Files?
At my current host, the server crashed and all data seemed to be lost. Lucky for us they had had a backup of all data which they put back on the server.

But now I get errors with some tables in phpMyAdmin where they show up as "in use" and when I view them I get the following error:

MySQL
#1033 - Incorrect information in file: *.frm
or

MySQL
#1016 - Can't open file: '*.InnoDB'. (errno: 1)

Because of the issues, they send me the *.frm, *.MYD and *.MYI files.
But am I able to view these files to see the structure or data?
And can I verify if structure or data is corrupt?

View Replies !
How To View Catalog In MySQL
How can I query mysql to view the catalog? (By the catalog I mean the
special internal database that holds the meta-information about all
other databases in the system, including descriptions of all the tables
and their fields.) I know how to do this in psql, so I imagine there
is a similar facility in mysql. FWIW, my OS is Linux.

View Replies !
Create View Statements
I've read the help page on the mysql.org site but still cannot get

create view employee as select emp.name from emp, dept where
dept.id=emp.dept;

The select statement works fine on its own and I've changed the view name
a couple of times to avoid reserved words but still get Error 1064 : you
have an error in your sql syntax near... which leaves me none the wiser.

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved