query-optimization

Where might I find a method to convert an arbitrary boolean expression into conjunctive or disjunctive normal form?

旧巷老猫 提交于 2019-12-03 11:59:51
I've written a little app that parses expressions into abstract syntax trees. Right now, I use a bunch of heuristics against the expression in order to decide how to best evaluate the query. Unfortunately, there are examples which make the query plan extremely bad. I've found a way to provably make better guesses as to how queries should be evaluated, but I need to put my expression into CNF or DNF first in order to get provably correct answers. I know this could result in potentially exponential time and space, but for typical queries my users run this is not a problem. Now, converting to CNF

How to search millions of record in SQL table faster?

99封情书 提交于 2019-12-03 11:55:50
问题 I have SQL table with millions of domain name. But now when I search for let's say SELECT * FROM tblDomainResults WHERE domainName LIKE '%lifeis%' It takes more than 10 minutes to get the results. I tried indexing but that didn't help. What is the best way to store this millions of record and easily access these information in short period of time? There are about 50 million records and 5 column so far. 回答1: Most likely, you tried a traditional index which cannot be used to optimize LIKE

T-SQL Where Clause Case Statement Optimization (optional parameters to StoredProc)

烂漫一生 提交于 2019-12-03 11:32:58
问题 I've been battling this one for a while now. I have a stored proc that takes in 3 parameters that are used to filter. If a specific value is passed in, I want to filter on that. If -1 is passed in, give me all. I've tried it the following two ways: First way: SELECT field1, field2...etc FROM my_view WHERE parm1 = CASE WHEN @PARM1= -1 THEN parm1 ELSE @PARM1 END AND parm2 = CASE WHEN @PARM2 = -1 THEN parm2 ELSE @PARM2 END AND parm3 = CASE WHEN @PARM3 = -1 THEN parm3 ELSE @PARM3 END Second Way:

Speeding up inner joins between a large table and a small table

▼魔方 西西 提交于 2019-12-03 10:34:43
问题 This may be a silly question, but it may shed some light on how joins work internally. Let's say I have a large table L and a small table S (100K rows vs. 100 rows). Would there be any difference in terms of speed between the following two options?: OPTION 1: OPTION 2: --------- --------- SELECT * SELECT * FROM L INNER JOIN S FROM S INNER JOIN L ON L.id = S.id; ON L.id = S.id; Notice that the only difference is the order in which the tables are joined. I realize performance may vary between

Optimizing select with transaction under SQLite 3

旧城冷巷雨未停 提交于 2019-12-03 08:35:33
问题 I read that wrapping a lot of SELECT into BEGIN TRANSACTION/COMMIT was an interesting optimization. But are these commands really necessary if I use " PRAGMA journal_mode = OFF " before? (Which, if I remember, disables the log and obviously the transaction system too.) 回答1: "Use transactions – even if you’re just reading the data. This may yield a few milliseconds." I'm not sure where the Katashrophos.net blog is getting this information, but wrapping SELECT statements in transactions does

How to properly index a many-many association table?

左心房为你撑大大i 提交于 2019-12-03 06:59:38
问题 In a typical many-many arrangement like this... Movies Actors Movies_Actors ------ ------ ------------- movie_ID actor_ID FK_movie_ID title name FK_actor_ID ... how should the association table ( 'Movies_Actors' ) be indexed for optimal read speed? I usually see this done only with the composite primary key in the association table, like so: CREATE TABLE Movies_Actors ( FK_movie_ID INTEGER, FK_actor_ID INTEGER, PRIMARY KEY (FK_movie_ID, FK_actor_ID) ) However, this seems like the index will

Optimising MySQL queries across hierarchical data

随声附和 提交于 2019-12-03 05:46:20
I have a fairly stable directed graph of order ~100k vertices and size ~1k edges. It is two-dimensional insofar as its vertices can be identified by a pair of integers (x, y) (of cardinality ~100 x ~1000) and all edges are strictly increasing in x . There is furthermore a dictionary of ~1k (key, val) pairs associated with each vertex. I am currently storing the graph in a MySQL database across three (InnoDB) tables: a table of vertices (which I don't think is relevant to my question, so I have omitted to include both it and the foreign key constraints that refer to it in my extracts below); a

optimize mysql count query

落爺英雄遲暮 提交于 2019-12-03 05:41:15
Is there a way to optimize this further or should I just be satisfied that it takes 9 seconds to count 11M rows ? devuser@xcmst > mysql --user=user --password=pass -D marctoxctransformation -e "desc record_updates" +--------------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+----------+------+-----+---------+-------+ | record_id | int(11) | YES | MUL | NULL | | | date_updated | datetime | YES | MUL | NULL | | +--------------+----------+------+-----+---------+-------+ devuser@xcmst > date; mysql --user=user --password=pass -D

How to make JOIN query use index?

亡梦爱人 提交于 2019-12-03 05:02:51
I have two tables: CREATE TABLE `articles` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(1000) DEFAULT NULL, `last_updated` datetime DEFAULT NULL, PRIMARY KEY (`id`), KEY `last_updated` (`last_updated`), ) ENGINE=InnoDB AUTO_INCREMENT=799681 DEFAULT CHARSET=utf8 CREATE TABLE `article_categories` ( `article_id` int(11) NOT NULL DEFAULT '0', `category_id` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`article_id`,`category_id`), KEY `category_id` (`category_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 | This is my query: SELECT a.* FROM articles AS a, article_categories AS c WHERE a.id = c

DB design and optimization considerations for a social application

别等时光非礼了梦想. 提交于 2019-12-03 03:40:22
The usual case. I have a simple app that will allow people to upload photos and follow other people. As a result, every user will have something like a "wall" or an "activity feed" where he or she sees the latest photos uploaded from his/her friends (people he or she follows). Most of the functionalities are easy to implement. However, when it comes to this history activity feed, things can easily turn into a mess because of pure performance reasons. I have come to the following dilemma here: i can easily design the activity feed as a normalized part of the database, which will save me writing