optimization

Slow SQL update could use some help.

An ex-coworker of mine wrote the following UPDATE as part of a data import script and it takes nearly 15 minutes to complete on a table of 92k rows. UPDATE table SET name = ( SELECT TOP 1 old_name FROM ( SELECT SUM(r) rev, number, name, intermediate_number, interm...

Slow MySQL retreival of the row with the largest value in indexed column

I have a SQL table readings something like: id int client_id int device_id int unique index(client_id, device_id) I do not understand why the following query is so slow: SELECT client_id FROM `readings` WHERE device_id = 10 ORDER BY client_id DESC LIMIT 1 My understanding with the index is that mysql keeps an ordered list (one prop...

How can I optimize or combine these MySQL queries?

I want to check for the username in the users table. If it's found, then I want to get the id. Otherwise, I want to insert the username as a new record, then get the id. Here's my code: <?PHP $sql = "SELECT id FROM users where username = '$username'"; $query = mysql_query($sql) or die(mysql_error()); $result = mysql_num_rows($query); if...

delete records from table using another table?

Hello note: to the editors: please edit the title if have a better one :) my question is: I have two tables in my database ----------- | table1 | |----------| | id | |text | =========== ----------- | table2 | |----------| | id | |text | ==========...

when a web applicattion generates excel and image files dinamically

Hi there In my web-application I have some forms and based to those forms, users will generate some excel and chart files(.xls and .png). Each use has to generate at least 2 excel files and 5 png files. The problem is that when is about to generate those files it takes 2 seconds for a excels file and 1 second for a chart. I'm using t...

Optimise a Query Which is taking too long to Run

Hi All, Im Using toad for Oracle to run a query which is taking much too long to run, sometimes over 15 minutes. The query is pulling memos which are left to be approved by managers. The query is not bringing back alot of rows. Typically when it is run it will return about 30 or 40 rows. The query needs to access a few tables for its...

Oracle Index Usage in View with Aggregates

Here's the background: Version: Oracle 8i (Don't hate me for being out of date. We are upgrading!) SQL> describe idcpdata Name Null? Type ----------------------------------------- -------- --------------------------- ID NOT NULL NUMBER(9) DAY ...

likely/unlikely equivalent for MSVC

GCC compiler supports __builtin_expect statement that is used to define likely and unlikely macros. eg. #define likely(expr) __builtin_expect((expr), !0) #define unlikely(expr) __builtin_expect((expr), 0) Is there an equivalent statement for the Microsoft Visual C compiler, or something equivalent ? ...

how to use Memcache to speed up the PHP?

Hello I have enabled the memcache extension for my PHP Apache localserver server (XAMPP) but I don't know how to use it to speed up my PHP scripts Is writing the following code in the top of every page I want to speed up is enough? or I should do something else? /* procedural API */ $memcache_obj = memcache_connect('127....

When do compilers inline C++ code?

In C++, do methods only get inlined if they are explicitly declared inline (or defined in a header file), or are compilers allowed to inline methods as they see fit? ...

How much memory does a Java object use when all its members are null?

Is it correct to assume a Java object only takes up the 8 bytes for the object reference as long as all it's members are set to null or does the definition of members already use up space in the instance for some reason? In other words, if I have a large collection of objects that I want to be space efficient, can I count on leaving unu...

T-SQL ISNULL() Optimization

I have this clause on a join in a stored procedure I inherited: WHERE a.is_active = 1 AND b.due_date <= ISNULL(@due_date_limit, b.due_date) How would I re-write this to remove the ISNULL as it's causing severe performance problems? ...

I need the most recent record in a join (PostgresSQL)

I have a table like so: call_activity ( call_id TEXT, activity_type TEXT, activity_time TIMESTAMP, PRIMARY KEY(call_id, activity_type, activity_time) ) activity_type may be one of about 9 different strings: 'started' 'completed' (about 5 variations on this) 'other' (these are the states that I want to display) A...

Can Java omit sending some headers in HTTP requests?

I'm using the HttpConnection class in Java to send HTTP requests. How do I omit unwanted HTTP headers? like: User-Agent Accept Accept-Language Accept-Encoding Accept-Charset Keep-Alive Connection Referer If-Modified-Since ...

common pre-mature optimizations and micro-optimizations

I've done a lot of relatively simple numerical programming, and a large amount of programming in general. In that time, I've found that a lot of people tend to perform what I call optimization by suspicion, or optimization by hearsay. Some of these really are optimizations (and indeed, some of them make a significant difference in actual...

Help optimizing MySQL query.

(Using MySQL 4.1.22) I can't get this query of mine to use an index on a large table(200k+ rows), it is doing a full table scan on it. The query takes about 1.2 seconds right now. I want to get it to less than .2 seconds if possible. Here is my query: SELECT st_issues.issue_id, st_issues.cat_id,st_categories.name AS cat_name, st_issue...

How to predict the behavior of a system based on previous behavior

I am looking for an algorithm that, based on the previous behavior of a system, predicts the future behavior. I'm building a parallel memory allocator that has a public list of empty blocks. Each thread, when it needs, can take blocks from this list and allocate from them. The blocks are grouped in bins, depending on the allocation si...

Group by string optimization

I'm gonna convert string to integer to optimize group by performance. What do you guys think of the idea? If applicable,then is there a built-in function to convert string to a unique integer in PHP? ...

Performance issue with Apache, PHP and Symfony~

Updated: ================================================================ I finally found the reason with oprofile. It was because the routing cache of Symfony. We have lots of pages with different urls and symfony caches them in one file (serialized data). So the cache file grows large and it needs more CPU to serialize and unserialize...

(Free) optimization programs for .Net-programs

What are the good (free) optimization programmers, .Net programmers need to have to optimize their programs? ...