database-optimization

Is inserting a new database entry faster than checking if the entry exists first?

泄露秘密 提交于 2019-12-10 13:04:00
问题 I was once told that it is faster to just run an insert and let the insert fail than to check if a database entry exists and then inserting if it is missing. I was also told that that most databases are heavily optimized for reading reading rather than writing, so wouldn't a quick check be faster than a slow insert? Is this a question of the expected number of collisions? (IE it's faster to insert only if there is a low chance of the entry already existing.) Does it depend on the database

How much size I will save if changed INT column to MEDIUMINT?

别来无恙 提交于 2019-12-08 15:42:52
I'm learning how to optimize my database by re choosing the correct data types for the columns and I want to know how much size I will save if I choose MEDIUMINT (3 Bytes) instead of INT (4 Bytes) AFAIK -and correct me if I'm wrong- I need the database size to be as small as possible to fit in RAM to reduce the hard-desk requests. The size of the database consists of the tables sizes + index sizes giving that I have an INT column that has 10'000'000 rows and a B-Tree index on it, how much size In MBs I will save if I changed the datatype of the column from INT to MEDIUMINT at table data size ?

Does GAE Datastore support eager fetching?

三世轮回 提交于 2019-12-08 02:39:35
问题 Let's say I want to display a list of books and their authors. In traditional database design, I would issue a single query to retrieve rows from the Book table as well as the related Author table, a step known as eager fetching . This is done to avoid the dreaded N+1 select problem : If the Author records were retrieved lazily, my program would have to issue a separate query for each author, possibly as many queries as there are books in the list. Does Google App Engine Datastore provide a

Should primary keys always be added to an innodb table?

做~自己de王妃 提交于 2019-12-07 05:20:09
问题 I have some innoDbs with only 2 int columns which are foreign keys to the primary keys of other tables. E.g one table is user_items, it has 2 columns, userId, itemId, both foreign keys to user and item tables, set to cascade if updated or deleted. Should I add a 3rd column to such tables and make it a primary key, or is it better the way it is right now, in terms of performance or any other benefits? 回答1: Adding a third ID column just for the sake of adding an ID column makes no sense. In

Does GAE Datastore support eager fetching?

孤者浪人 提交于 2019-12-06 13:57:21
Let's say I want to display a list of books and their authors. In traditional database design, I would issue a single query to retrieve rows from the Book table as well as the related Author table, a step known as eager fetching . This is done to avoid the dreaded N+1 select problem : If the Author records were retrieved lazily, my program would have to issue a separate query for each author, possibly as many queries as there are books in the list. Does Google App Engine Datastore provide a similar mechanism, or is the N+1 select problem something that is no longer relevant on this platform? I

Should primary keys always be added to an innodb table?

六月ゝ 毕业季﹏ 提交于 2019-12-05 10:33:03
I have some innoDbs with only 2 int columns which are foreign keys to the primary keys of other tables. E.g one table is user_items, it has 2 columns, userId, itemId, both foreign keys to user and item tables, set to cascade if updated or deleted. Should I add a 3rd column to such tables and make it a primary key, or is it better the way it is right now, in terms of performance or any other benefits? Adding a third ID column just for the sake of adding an ID column makes no sense. In fact it simply adds processing overhead (index maintenance) when you insert or delete rows. A primary key is

MYSQL database optimization using indexing [closed]

≯℡__Kan透↙ 提交于 2019-12-02 23:37:06
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I am working on LearnBiz Simulations, a self-funded start-up which makes simulations for the domain of management education. (a) Our website is currently catering to about 16k people. Currently, size of database is 30 mb with a total of about 90 tables and each table may have anywhere between 5 to 50 columns.

MYSQL database optimization using indexing [closed]

前提是你 提交于 2019-12-02 13:27:52
I am working on LearnBiz Simulations , a self-funded start-up which makes simulations for the domain of management education. (a) Our website is currently catering to about 16k people. Currently, size of database is 30 mb with a total of about 90 tables and each table may have anywhere between 5 to 50 columns. All our tables in the database, repeatedly have new rows of insertions, deletions or updations. But no columns are ever added. Does it create any issues with employing indexing techniques? There were a couple of other forums and videos which suggests that even inserting or deleting a row

Optimising MySQL queries with heavy joins

偶尔善良 提交于 2019-12-01 06:34:32
问题 I currently run a site which tracks up-to-the-minute scores and ratings in a list. The list has thousands of entries that are updated frequently, and the list should be sortable by these score and ratings columns. My SQL for getting this data currently looks like (roughly): SELECT e.*, SUM(sa.amount) AS score, AVG(ra.rating) AS rating FROM entries e LEFT JOIN score_adjustments sa ON sa.entry_id = e.id HAVING sa.created BETWEEN ... AND ... LEFT JOIN rating_adjustments ra ON ra.entry_id = e.id

Solution for speeding up a slow SELECT DISTINCT query in Postgres

你。 提交于 2019-11-30 07:59:58
The query is basically: SELECT DISTINCT "my_table"."foo" from "my_table" WHERE... Pretending that I'm 100% certain the DISTINCT portion of the query is the reason it runs slowly, I've omitted the rest of the query to avoid confusion, since it is the distinct portion's slowness that I'm primarily concerned with (distinct is always a source of slowness). The table in question has 2.5 million rows of data. The DISTINCT is needed for purposes not listed here (because I don't want back a modified query, but rather just general information about making distinct queries run faster at the DBMS level,