database-optimization

Optimal database structure - 'wider' table with empty fields or greater number of tables?

落爺英雄遲暮 提交于 2019-11-30 03:52:33
I need to fit in additional data into a database, and I have a choice between modifying an existing table (table_existing) or creating new tables. This is how table_existing looks like right now: table_existing ------------------------- | ID | SP | SV | Field1 | | .. | WW | 1 | ...... | | .. | WW | 1 | ...... | ------------------------- Option (A) table_existing ---------------------------------------------------------------------- | ID | SP | SV | Field1 | Field2 | Field3 | Field4 | Field5 | Field6 | | .. | XX | 1 | ...... | ...... | ...... | ...... | ...... | ...... | | .. | YY | 2 | ......

One big query vs. many small ones?

谁说胖子不能爱 提交于 2019-11-29 13:53:33
I'd like to know, which option is the most expensive in terms of bandwith and overall efficiency. Let's say I have a class Client in my application and a table client in my database. Is it better to have one static function Client.getById that retrieves the whole client record or many ( Client.getNameById , Client.getMobileNumberById , etc.) that retrieve individual fields? If a single record has a lot of fields and I end up using one or two in the current script, is it still better to retrieve everything and decide inside the application what to do with all the data? I'm using PHP and MySQL

Solution for speeding up a slow SELECT DISTINCT query in Postgres

两盒软妹~` 提交于 2019-11-29 11:16:49
问题 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

Optimal database structure - 'wider' table with empty fields or greater number of tables?

左心房为你撑大大i 提交于 2019-11-29 00:49:03
问题 I need to fit in additional data into a database, and I have a choice between modifying an existing table (table_existing) or creating new tables. This is how table_existing looks like right now: table_existing ------------------------- | ID | SP | SV | Field1 | | .. | WW | 1 | ...... | | .. | WW | 1 | ...... | ------------------------- Option (A) table_existing ---------------------------------------------------------------------- | ID | SP | SV | Field1 | Field2 | Field3 | Field4 | Field5 |

How do I know when to index a column, and with what?

我们两清 提交于 2019-11-28 20:07:19
问题 In docs for various ORMs they always provide a way to create indexes, etc. They always mention to be sure to create the appropriate indexes for efficiency, as if that is inherent knowledge to a non-hand-written-SQLer who needs to use an ORM. My understanding of indexes (outside of PK) is basically: If you plan to do LIKE queries (ie, search) based on the contents of a column, you should use a full text index for that column. What else should I know regarding indexes (mostly pertaining to

Delete statement in SQL is very slow

元气小坏坏 提交于 2019-11-28 15:28:23
问题 I have statements like this that are timing out: DELETE FROM [table] WHERE [COL] IN ( '1', '2', '6', '12', '24', '7', '3', '5') I tried doing one at a time like this: DELETE FROM [table] WHERE [COL] IN ( '1' ) and so far it's at 22 minutes and still going. The table has 260,000 rows in it and is four columns. Does anyone have any ideas why this would be so slow and how to speed it up? I do have a non-unique, non-clustered index on the [COL] that i'm doing the WHERE on. I'm using SQL Server

One big query vs. many small ones?

牧云@^-^@ 提交于 2019-11-28 07:51:57
问题 I'd like to know, which option is the most expensive in terms of bandwith and overall efficiency. Let's say I have a class Client in my application and a table client in my database. Is it better to have one static function Client.getById that retrieves the whole client record or many ( Client.getNameById , Client.getMobileNumberById , etc.) that retrieve individual fields? If a single record has a lot of fields and I end up using one or two in the current script, is it still better to