indexing

What is a SPATIAL INDEX and when should I use it?

浪尽此生 提交于 2019-12-20 09:46:31
问题 Like most of the average PHP web developers I use MySql as a RDBMS. MySql (as other RDBMS also) offers SPATIAL INDEX features, but I'm don't get it very well. I have googled for it but didn't find clear real world examples to clarify my bad knowledge about it. Could someone explain me a little bit what is a SPATIAL INDEX and when should I use it? 回答1: You can use a spatial index for indexing geo-objects - shapes. The spatial index makes it possible to efficiently search for objects that

Indexing a mysql table for geo lookup using latitude/longitude

余生长醉 提交于 2019-12-20 09:45:53
问题 I have a legacy innodb table Listing containing a business with latitude/longitude. Given an input latitude/longitude (below 51.2167/4.41667), the query is to return the first active, enabled, not-deleted 30 businesses in order of proximity (kilometers). A join with the accounts table is made to check the validity of the listing. select listing.* from listing listing , account account where listing.account_id = account.id and listing.active = 1 and listing.approved = 1 and listing.deleted = 0

In which cases will Oracle create indexes automatically?

心不动则不痛 提交于 2019-12-20 09:36:46
问题 As far as I know (this page) Oracle automatically creates an index for each UNIQUE or PRIMARY KEY declaration. Is this a complete list of cases when indexes are created automatically in Oracle? 回答1: I'll try to consolidate given answers and make it community wiki. So indexes are automatically created by Oracle for such cases: APC: For primary key and unique key unless such indexes already exist. APC: For LOB storage and XMLType. Gary: For table with a nested table. Jim Hudson: For

What is the difference between OFFLINE and ONLINE index rebuild in SQL Server?

旧街凉风 提交于 2019-12-20 09:27:15
问题 When rebuilding an index, there is an option for ONLINE=OFF and ONLINE=ON. I know that when ONLINE mode is on, it makes a copy of the index, switches new queries to utilizing it, and then rebuilds the original index, tracking changes using versioning to both (correct me if I am wrong). But what does SQL do in OFFLINE mode? 回答1: In ONLINE mode the new index is built while the old index is accessible to reads and writes. any update on the old index will also get applied to the new index. An

what does a B-tree index on more than 1 column look like?

青春壹個敷衍的年華 提交于 2019-12-20 09:21:23
问题 So I was reading up on indexes and their implementation, and I stumbled upon this website that has a brief explanation of b-tree indexes: http://20bits.com/articles/interview-questions-database-indexes/ The b-tree index makes perfect sense for indexes that are only on a single column, but let's say I create an index with multiple columns, how then does the b-tree work? What is the value of each node in the b-tree? For example, if I have this table: table customer: id number name varchar phone

PostgreSQL: How to index all foreign keys?

蹲街弑〆低调 提交于 2019-12-20 09:13:48
问题 I am working with a large PostgreSQL database, and I am trying to tune it to get more performance. Our queries and updates seem to be doing a lot of lookups using foreign keys. What I would like is a relatively simple way to add Indexes to all of our foreign keys without having to go through every table (~140) and doing it manually. In researching this, I've come to find that there is no way to have Postgres do this for you automatically (like MySQL does), but I would be happy to hear

Why does PostgresQL query performance drop over time, but restored when rebuilding index

不问归期 提交于 2019-12-20 09:01:06
问题 According to this page in the manual, indexes don't need to be maintained . However, we are running with a PostgresQL table that has a continuous rate of updates , deletes and inserts that over time (a few days) sees a significant query degradation. If we delete and recreate the index, query performance is restored. We are using out of the box settings. The table in our test is currently starting out empty and grows to half a million rows. It has a fairly large row (lots of text fields). We

Adding indexes to SQLAlchemy models after table creation

余生长醉 提交于 2019-12-20 08:57:46
问题 I have a flask-sqlalchemy model: class MyModel(db.Model): __tablename__ = 'targets' id = db.Column(db.Integer, primary_key=True) url = db.Column(db.String(2048)) The table has already been created, and is in use. I want to create an index on the url attribute, so I pass index=True to it: url = db.Column(db.String(2048), index=True) How can I make this index take effect, without deleting and recreating the table? 回答1: Given the model class from the original question. class MyModel(db.Model): _

Need two indexes on a HABTM join table?

≯℡__Kan透↙ 提交于 2019-12-20 08:56:43
问题 A simple has_and_belongs_to_many association: Person has_and_belongs_to_many :products Product has_and_belongs_to_many :persons Are both of the following indexes helpful for optimal performance? add_index :person_products, [:person_id, :product_id] add_index :person_products, [:product_id, :person_id] 回答1: Close - you most likely want the following: add_index :person_products, [:person_id, :product_id], :unique => true add_index :person_products, :product_id The :unique => true is not

Best of breed indexing data structures for Extremely Large time-series

江枫思渺然 提交于 2019-12-20 08:45:06
问题 I'd like to ask fellow SO'ers for their opinions regarding best of breed data structures to be used for indexing time-series (aka column-wise data, aka flat linear). Two basic types of time-series exist based on the sampling/discretisation characteristic: Regular discretisation (Every sample is taken with a common frequency) Irregular discretisation(Samples are taken at arbitary time-points) Queries that will be required: All values in the time range [t0,t1] All values in the time range [t0