relational-database

Why this mysql query (with is null check) is so slower than this other one?

泪湿孤枕 提交于 2020-01-23 19:28:15
问题 I getting in doubt with "IS NULL" MySQL check. I have this 2 queries. The first one runs in about 300 seconds. The second one run less then 1 second! Slow query: SELECT count(distinct(u.id)) FROM ips_usuario AS u JOIN ips_fatura AS f ON ((u.id = f.ips_usuario_id) OR (u.ips_usuario_id_titular IS NOT NULL AND u.ips_usuario_id_titular = f.ips_usuario_id)); Fast query: SELECT count(distinct(u.id)) FROM ips_usuario AS u JOIN ips_fatura AS f ON ((u.id = f.ips_usuario_id) OR (u.ips_usuario_id

How can I relate a primary key field to multiple tables?

血红的双手。 提交于 2020-01-21 18:54:27
问题 I have 4 tables: User Reports Photos Locations I am allowed to report photos, users, and locations. The primary key of my Reports table is ( User_Id, Reported_Id ) Reported_Id could belong to any of these 3: photos , users and locations . How can I represent this relationship in an entity relationship model? 回答1: The Problem You cannot do this - a foreign key (Reported_Id) cannot reference three tables at once Seems to be a problem regarding the understnading of the data ... rather than a

How can I relate a primary key field to multiple tables?

☆樱花仙子☆ 提交于 2020-01-21 18:54:20
问题 I have 4 tables: User Reports Photos Locations I am allowed to report photos, users, and locations. The primary key of my Reports table is ( User_Id, Reported_Id ) Reported_Id could belong to any of these 3: photos , users and locations . How can I represent this relationship in an entity relationship model? 回答1: The Problem You cannot do this - a foreign key (Reported_Id) cannot reference three tables at once Seems to be a problem regarding the understnading of the data ... rather than a

Designing relationships around an inheritance structure

坚强是说给别人听的谎言 提交于 2020-01-21 05:45:08
问题 I have a conceptual question regarding how best to organise my database. Currently I have four core tables users , teachers , students and notifications . However both the teachers and students tables inherit from the users table so contain the foreign key user_id . The notifications table as you might have guessed refers to notifications. These need to appear for all users that belong to an employee group i.e. under the employment of another. Both students and teachers can employ other users

Select all rows that have at least a list of features

大憨熊 提交于 2020-01-20 08:48:07
问题 I have EXPERIMENTAL_RUNS (runId), each of which have any number of SENSORS (sensorId) associated with them. With that in mind, I have an RS table to join the two: ========== RS ========== runId, sensorId Thus if the run with runId=1 had sensors with sensorId=1, sensorId=6, sensorId=8 in it, there would be 3 entries in the RS table: (runId=1, sensorId=1) (runId=1, sensorId=6) (runId=1, sensorId=8) Is this really how I would return all EXPERIMENTAL_RUNS that have sensors {11,13,15}? From what I

ERD draft for creating grouped data collection list

我与影子孤独终老i 提交于 2020-01-17 08:25:09
问题 This is a follow up question for Table design about sets of data collection elements as I am still trying to come up with a design. What I would like to do is to be able to pre-define what study/protocol pair requires as a data collection to be displayed like a to-do list or checklist which can be tracked at clinic visits for patients. Attached is what I have so far with possible examples in each table but I have never implemented supertype/subtype relationship so I am not sure if I am on the

Do all relationships modeled in SQLAlchemy have to be bi-directional?

早过忘川 提交于 2020-01-17 06:44:49
问题 I am learning python and sqlalchemy and modelled this relationship between shops and locale. I get the error: InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers. Triggering mapper: 'Mapper|Shop|shop'. Original exception was: Mapper 'Mapper|Locale|locale' has no property 'shop' when I try to retrieve a lolcale from the db. from sqlalchemy import Column, ForeignKey, PrimaryKeyConstraint, String from sqlalchemy.orm import

Establishing relationships through a common table the right way

痞子三分冷 提交于 2020-01-17 06:19:14
问题 I have three tables inside of a database: interest , subscription and subscriber . The schema looks like this: The subscription table has a one to many relationship on both interest and subscriber. How I would like it to work, and I'm not sure if how I want it to work and how it's actually working are lining up, but it should be like this: a Subscriber can have multiple Interests, and each Interest can have multiple Subscribers. This will allow me to see which interests a subscriber has, and

How to update fields based on value of other record

风格不统一 提交于 2020-01-17 04:59:25
问题 I have a table resembling the following structure: City start_date end_date Paris 1995-01-01 00:00:00 1997-10-01 23:59:59 Paris 1997-10-02 00:00:00 0001-01-01 00:00:00 Paris 2013-01-25 00:00:00 0001-01-01 00:00:00 Paris 2015-04-25 00:00:00 0001-01-01 00:00:00 Berlin 2014-11-01 00:00:00 0001-01-01 00:00:00 Berlin 2014-06-01 00:00:00 0001-01-01 00:00:00 Berlin 2015-09-11 00:00:00 0001-01-01 00:00:00 Berlin 2015-10-01 00:00:00 0001-01-01 00:00:00 Milan 2001-01-01 00:00:00 0001-01-01 00:00:00

How to get child record (case class) ID in Play Framework (2.4.0) using Forms

你说的曾经没有我的故事 提交于 2020-01-17 03:44:31
问题 I'm afraid I'm not seeing it yet. There must be a way, using the tools as they are intended to be used, to get the ID of a child record (many-to-one typical relational database stuff) of a series of "items" I can create a "form" (mapping) in the case class of the parent no problem. lazy val aForm = Form( mapping( "ID" -> ignored(id), "firstName" -> nonEmptyText, "lastName" -> nonEmptyText, "listOfEmails" -> seq(email), "statusID" -> ignored(0l), "roleID" -> default(longNumber, roleID),