mysql

Index on Composite attributes

瘦欲@ 提交于 2021-02-10 05:38:25
问题 When we create an index on an attribute a tree is created for this attribute. But what happens when we create an index with composite attributes? Two trees are created? Both are part of the same tree? What? 回答1: It concats the attributes in the same order as you have mentioned. It for the same reason, if you have an composite index on columns a,b,c in the same order, the index will be useful only if the left columns are searched WHERE a=4 ## uses index WHERE a=4 and b=10 ## uses index WHERE b

Mutually exclusive values in SQL

女生的网名这么多〃 提交于 2021-02-10 05:38:21
问题 I have a query which selects products from a table. A product can have multiple prices (think of various prices) and a default price. Naturally, this is a one-to-many relation. I need to select the products which have a given price, or the default price - which means mutual exclusion. I know this can be done through separate queries and a WHERE (not) IN clauses or a union statement, but I'm convinced a more optimal way must be possible. My query currently looks like this: SELECT products.*,

Does the order of tables in straight joins, with no hint directives, affect performance?

折月煮酒 提交于 2021-02-10 05:38:16
问题 All SQL-based RDBMS' (versions up to 10 years old): Does the order of tables in a straight join query (with no hint directives) make a difference for optimum performance and memory management? I heard that the last join should be the largest table. How does your DB's query optimizer handle this scenario? 回答1: Just to add more on the subject... YES and NO, depends. That is my answer. It depends on many factors, wich RDBMS you are using (MySQL, MSSQL Server, Oracle, DB2...), type of join, size

Does the order of tables in straight joins, with no hint directives, affect performance?

£可爱£侵袭症+ 提交于 2021-02-10 05:38:12
问题 All SQL-based RDBMS' (versions up to 10 years old): Does the order of tables in a straight join query (with no hint directives) make a difference for optimum performance and memory management? I heard that the last join should be the largest table. How does your DB's query optimizer handle this scenario? 回答1: Just to add more on the subject... YES and NO, depends. That is my answer. It depends on many factors, wich RDBMS you are using (MySQL, MSSQL Server, Oracle, DB2...), type of join, size

Symfony: Base table or view already exists: 1050 Table 'migration_versions' already exists

寵の児 提交于 2021-02-10 05:15:31
问题 I've done something horribly wrong to my migration_versions, deleted the versions from the migrations folder now and I get this error when try to run anything to do with migrations. Could someone point me in the direction of where to start to fix this? If I drop the database and then make:migration , the migration_versions table appears in the db. After that if I try to run php bin/console doctrine:migrations:migrate I get the error: In AbstractMySQLDriver.php line 38: An exception occurred

Symfony: Base table or view already exists: 1050 Table 'migration_versions' already exists

人盡茶涼 提交于 2021-02-10 05:15:27
问题 I've done something horribly wrong to my migration_versions, deleted the versions from the migrations folder now and I get this error when try to run anything to do with migrations. Could someone point me in the direction of where to start to fix this? If I drop the database and then make:migration , the migration_versions table appears in the db. After that if I try to run php bin/console doctrine:migrations:migrate I get the error: In AbstractMySQLDriver.php line 38: An exception occurred

How should I unit test MySQL queries?

我的未来我决定 提交于 2021-02-10 05:12:49
问题 I'm building some unit tests for my Python module which interfaces with a MySQL database via SQLAlchemy. From reading around I gather the best way to do this is to create a test database that I can query as if it was the real thing. I've done this however how should I test the existing queries in the module as they currently all point at the live database? The only idea I'd come up with was to do something like the following: def run_query(engine, db_name='live_db') engine.execute(f'SELECT *

MySQL - universal way of getting approx. row size in bytes

末鹿安然 提交于 2021-02-10 04:56:15
问题 OK, I won't be mad if nobody wants to help me with this nonsense, but I wanted to have a way to get the approximate row by row byte size of a table in a MySQL console (well I'm using phpMyAdmins SQL window). The inner query reads the desired table columns from the schema and group_concats them to a to a statement, while adding the char_length() function to every column name. I did not find a better way, than using SEPARATOR for this, but as the separator comes first after the first element, I

sql return only max date for each id

痴心易碎 提交于 2021-02-10 04:53:42
问题 I have a database with one table that looks like this Books(id, title, author_id, date) I am using type DATE for the date field. What the query is looking to do is return only the most recent book from each author, so even for the books that have the same author_id, only return the book that has the most recent date field for that author. So for all books find the most recent book from each author, returning title, author_id, and date. I believe I will need to use the MAX function with a

sql return only max date for each id

泄露秘密 提交于 2021-02-10 04:53:35
问题 I have a database with one table that looks like this Books(id, title, author_id, date) I am using type DATE for the date field. What the query is looking to do is return only the most recent book from each author, so even for the books that have the same author_id, only return the book that has the most recent date field for that author. So for all books find the most recent book from each author, returning title, author_id, and date. I believe I will need to use the MAX function with a