Showing entries 21 to 27
« 10 Newer Entries
Displaying posts with tag: queries (reset)
The “Shadow Table” trick.

The need: Often there is a requirement where data in a particular table has to be processed, and the data processing might be slow, while the table might be a one that is used by your application extensively. For example, a logging table that logs page hits. Or there might be an archiving operation that has to be performed on a particular table. Archiving / processing / aggregating records, all these operations are slow and can really blog down a website, combine that with the added overhead if the table that needs to have these operations performed is one that...

Performance tuning using vertical partitioning.

Does having small data-sets really help? Of course it does! Are memory lookups faster that disk lookups. Of course ! So many times I have seen people complain about queries taking too long now, while they were not taking that long earlier. There is one big reason for this, earlier the size of data-set was small so it could fit into memory. Now that the data-set has grown large enough that it cannot fit entirely into memory, the disk seeks really have slowed down the queries significantly. What to do now? Vertical partitioning. Divide the data-set into separate data-sets vertically....

Keeping save – Injection attacks etc.

I had someone point out to me that some of the sample code I have used might be vulnerable to an insertion attack. So I feel it is time to address this subject.

First when using examples I try to just focus on the subject of the current blog and often strip a lot of things that are irrelevant to the point I am trying to make out. But now to the subject of keeping your code save.

If you write and SQL statement looking something like

lc_sql = “SELECT * from customer WHERE custno = ‘” + lc_custno + “‘”

Someone could enter “‘; TRUNCATE TABLE customer;’” resulting in  a SQL statement looking like

SELECT * from customer WHERE custno = ”; TRUNCATE TABLE customer; ”

Which could be quite disasterous. So to avoid this we could use parameterized queries which I cannot as I am using a seperate function to wrap around the SQLEXEC() function to do all kinds of things like …

[Read more]
Converting and optimizing SQL Statements

Now it became time to conveert some SQL statements. Even though many SELECT SQL statements will run unchanged in MYSQL it might be wise to check and see if they are performing well. There are some differences in how VFP and MYSQL optimize queries and a query that just performs great in VFP might be very slow in MYSQL. And then there are some cases where we have to replace things that are possible in VFP but not supported in MYSQL.

First lets assume that our tables all have lots of records. After all it does not pay to spend time on optimizing on tables with a few dozend records. I also will not go into VFP optimization here as this is a MYSQL blog.

Lets assume for our first case we might have a table with invoice detail records and a table with items that are on sale. So now we want to get maybe 2 queries. One to show a total of all the items that were on sale and the second a total of all the items not on sale. I will leave …

[Read more]
Materialized view makes login process 25k times faster

It may sound like a dramatic number, and that’s because it is. One thing that is enjoyable about working on beta applications is finding new solutions and better methods to improve the user experience. The original method for displaying the recent addition of overview analytics data in the beta version of Kontrollbase was to run [...]

MySQL challenge: LIMIT rows accessed

I read Baron's blog about this challenge on how to limit rows accessed, not rows returned with a query. He had another requirement, no subqueries, so it would work on pre MySQL 4.x. At first, I started down the same path he did, looking for a way to limit the number of rows accessed. The only way I could do it was to either create 4 seperte queries directly spelling out which actor_id I was looking for. I could also use an IN clause as well, but that wasn't generic enough for me. There's got to be a way to avoid a full table scan and only access a minimum number of rows to return the result he was looking for.

In researching LIMIT optimization, the MySQL 5.0 reference manual states:

If you use LIMIT row_count with …

[Read more]
MySQL challenge: LIMIT rows accessed

I read Baron's blog about this challenge on how to limit rows accessed, not rows returned with a query. He had another requirement, no subqueries, so it would work on pre MySQL 4.x. At first, I started down the same path he did, looking for a way to limit the number of rows accessed. The only way I could do it was to either create 4 seperte queries directly spelling out which actor_id I was looking for. I could also use an IN clause as well, but that wasn't generic enough for me. There's got to be a way to avoid a full table scan and only access a minimum number of rows to return the result he was looking for.

In researching LIMIT optimization, the MySQL 5.0 reference manual states:

If you use LIMIT row_count with …

[Read more]
Showing entries 21 to 27
« 10 Newer Entries