database-performance

Why MongoDB different query plans show different nReturned value?

我的未来我决定 提交于 2019-12-06 09:39:21
I have a collection faults in my MongoDB database which every document has these fields: rack_name , timestamp Just for sake of testing and comparing performances, I have created these two indexes: rack -> {'rack_name': 1} and time -> {'timestamp': 1} Now I executed the following query with explain(): db.faults.find({ 'rack_name': { $in: [ 'providence1', 'helena2' ] }, 'timestamp': { $gt: 1501548359000 } }) .explain('allPlansExecution') and here is the result: { "queryPlanner" : { "plannerVersion" : 1, "namespace" : "quicktester_clone.faults", "indexFilterSet" : false, "parsedQuery" : { "$and"

Why is using an INT to select a Varchar index containing numbers much slower than using Strings?

江枫思渺然 提交于 2019-12-06 04:39:15
问题 I have a table that contains several thousand rows, having a Varchar column that contains numbers. Despite discussing why this column is not a numeric type then, selecting rows from that table showed a strange behavior. Although there is an index on that column, using numeric strings to find a row is MUCH faster (0.01 secs) than using Ints (0.54 secs). What is the reason for this? It seems not to be able to cast and use the value for the index... Am I overlooking something? It looks like it

RDBMS impact on Golang [closed]

点点圈 提交于 2019-12-06 03:38:34
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . I'm not going to make a big long rattle on this question about what I've tested and number crunching. I'm more interested in actual up-to-date practice performances. I've read tons of articles already and some of them are pretty skeptical or either very pro to one library . I

Reuse mysql Subquery in InnerJoin

一笑奈何 提交于 2019-12-05 20:42:50
I'm trying optimizing a query, trying to avoid repeating the query indicated with " COMPLEX QUERY ", that is used 2 times and both, has the same results. The original query SELECT news.* FROM news INNER JOIN((SELECT myposter FROM (SELECT **COMPLEX QUERY**)) UNION (SELECT myposter FROM `profiles_old` prof2 WHERE prof2.profile_id NOT IN (SELECT **COMPLEX QUERY**))) r ON news.profile = r.p I was wondering if something like this was possible: SELECT news.* FROM (SELECT **COMPLEX QUERY**) complexQuery, news INNER JOIN ((SELECT myposter FROM complexquery) UNION (SELECT myposter FROM `profiles_old`

Does a postgres foreign key imply an index?

青春壹個敷衍的年華 提交于 2019-12-05 19:50:35
问题 I have a postgres table (lets call this table Events ) with a composite foreign key to another table (lets call this table Logs ). The Events table looks like this: CREATE TABLE Events ( ColPrimary UUID, ColA VARCHAR(50), ColB VARCHAR(50), ColC VARCHAR(50), PRIMARY KEY (ColPrimary), FOREIGN KEY (ColA, ColB, ColC) REFERENCES Logs(ColA, ColB, ColC) ); In this case, I know that I can efficiently search for Events by the primary key, and join to Logs. What I am interested in is if this foreign

How to improve performance of a function with cursors in PostgreSQL?

孤者浪人 提交于 2019-12-05 18:35:29
I have function with two nested cursors. The outer cursor gets payment details of a customer from the source and inserts into the target based on some business logic. The inner cursor takes the payment details of each payment, it happens one after another. The payments table has about 125000 rows, and about 335000 rows for payment details. All of these rows are to be migrated to a target table. Executing the function takes over two hours and the database CPU usage goes up to 99%. I am working with PostgreSQL 9.2. How can I improve the performance of the function? The code I am using: CREATE OR

SQL Geometry VS decimal(8,6) Lat, Long Performance

笑着哭i 提交于 2019-12-05 15:36:25
I was looking into performance of selecting closest points within certain proximity to given coordinate. Options are to ether use two decimal(8,6) - lat, long columns or single geography column and work with that. I am only interested which is faster? Matas Vaitkevicius TL;DR Geography is ~10 times faster. Ok so I have set up test: Couple of tables one with id,lat,long (int, decimal(8,6),decimal(8,6)) other with id,coord (int, geography) . Then insert 47k of random data. For indexing first table I used nonclustered Ascending index on lat,long with fill factor of 95. for second one GRIDS =

Dropping column in Postgres on a large dataset

天大地大妈咪最大 提交于 2019-12-05 12:08:20
问题 So I have a table with a large dataset and this table has a three columns that I would like to drop. The question is: how will Postgres deal with it? Will it walk through every entry or will it just update mapping info without much overhead? Can I just make an ALTER TABLE or should I use swap-table in this particular case? And, if it makes any difference, all three columns have fixed length (two integers and one numeric). I'm sorry if it's been asked already, but Google couldn't find any

How reliable is the cost measurement in PostgreSQL Explain Plan?

狂风中的少年 提交于 2019-12-05 11:32:44
The queries are performed on a large table with 11 million rows. I have already performed an ANALYZE on the table prior to the query executions. Query 1: SELECT * FROM accounts t1 LEFT OUTER JOIN accounts t2 ON (t1.account_no = t2.account_no AND t1.effective_date < t2.effective_date) WHERE t2.account_no IS NULL; Explain Analyze: Hash Anti Join (cost=480795.57..1201111.40 rows=7369854 width=292) (actual time=29619.499..115662.111 rows=1977871 loops=1) Hash Cond: ((t1.account_no)::text = (t2.account_no)::text) Join Filter: ((t1.effective_date)::text < (t2.effective_date)::text) -> Seq Scan on

UPDATE vs UPDATE WHERE

瘦欲@ 提交于 2019-12-05 10:27:35
I have a table with many rows, where I periodically want to set one column to 0 using a cron. What is faster / less memory consuming, doing an UPDATE on all rows (ie. no WHERE clause) or doing an UPDATE only WHERE mycolumn != 0 ? chesterbr As noticed in comments on the original post, it depends on several things (index, database engine, type of storage media, available cache memory, etc.). We could make an educated guess that: a) We should always have a full-table scan unless we have an index on the column (and I'd not recommend one just for the sake of this query, as you will penalize down