<div dir="ltr">I think adding a separate UUID column seems like a feasible workaround for Content without a natural key. But I can understand the desire not to do so in order to create an artificial natural key. <div><br></div><div>I guess we can weigh the performance results of using UUID PKs against how often we expect plugin Content to have no natural key.<br clear="all"><div><div dir="ltr" class="m_-5149735033184441595m_-7955058730495210454gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><br></div><div>David<br></div></div></div></div></div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jan 3, 2019 at 2:28 PM Simon Baatz <<a href="mailto:gmbnomis@gmail.com" target="_blank">gmbnomis@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Thu, Jan 03, 2019 at 01:02:57PM -0500, David Davis wrote:<br>
>    I don't think that using integer ids with bulk_create and supporting<br>
>    mysql/mariadb are necessarily mutually exclusive. I think there might<br>
>    be a way to find the records created using bulk_create if we know the<br>
>    natural key. It might be more performant than using UUIDs as well.<br>
<br>
This assumes that there is a natural key.  For content types with no<br>
digest information in the meta data, there may be a natural key<br>
for content within a repo version only, but no natural key for the<br>
overall content.  (If we want to support non-immediate modes for such<br>
content.  In immediate mode, a digest can be computed from the<br>
associated artifact(s)).<br>
<br>
Of course, there are ways around that (use a UUID as the "natural" key,<br>
or add a UUID to the repo version key fields), but I would like to<br>
avoid that.<br>
<br>
>    On Thu, Jan 3, 2019 at 11:04 AM Dennis Kliban <[1]<a href="mailto:dkliban@redhat.com" target="_blank">dkliban@redhat.com</a>><br>
>    wrote:<br>
> <br>
>    Thank you Daniel for the explanation and for filing an issue[0] to do<br>
>    performance analysis of UUIDs.<br>
>    I really hope that we can switch back to using UUIDs so we can bring<br>
>    back MariaDB support for Pulp 3.<br>
>    [0] [2]<a href="https://pulp.plan.io/issues/4290" rel="noreferrer" target="_blank">https://pulp.plan.io/issues/4290</a><br>
> <br>
>    On Wed, Dec 5, 2018 at 1:35 PM Daniel Alley <[3]<a href="mailto:dalley@redhat.com" target="_blank">dalley@redhat.com</a>><br>
>    wrote:<br>
> <br>
>    To rephrase the problem a little bit:<br>
>    We need to bulk_create() a bunch of objects, and then after we do that<br>
>    we want to immediately be able to relate them with other objects, which<br>
>    means we need their PKs of the objects that were just created.<br>
>    In the case of auto-increment integer PKs, we can't know that PK value<br>
>    before it gets saved into the database.  Luckily, PostgreSQL (and<br>
>    Oracle) support a "RETURNING" keyword that does provides this<br>
>    information.  The raw SQL would look something like this:<br>
> <br>
> INSERT INTO items (name) values ('bear') RETURNING id;<br>
> <br>
>    Django uses this feature to set the PK field on the model objects it<br>
>    returns when you call bulk_create() on a list of unsaved model objects.<br>
>    Unfortunately, MySQL doesn't support this, so there's no way to figure<br>
>    out what the PKs of the objects you just saved were, so the ORM can't<br>
>    set that information on the returned model objects.<br>
>    UUID PKs circumvent this because the PK gets created outside of the<br>
>    database, prior to being saved in the database, and so Django *can*<br>
>    know what the PK will be when it gets saved.<br>
> <br>
>    On Wed, Dec 5, 2018 at 12:11 PM Brian Bouterse <[4]<a href="mailto:bbouters@redhat.com" target="_blank">bbouters@redhat.com</a>><br>
>    wrote:<br>
> <br>
>    +1 to experimentation and also making sure that we understand the<br>
>    performance implications of the decision. I'm replying to this earlier<br>
>    note to restate my observations of the problem a bit more.<br>
>    More ideas and thoughts are welcome. This is a decision with a lot of<br>
>    aspects to consider.<br>
>    On Tue, Nov 20, 2018 at 10:00 AM Patrick Creech <[5]<a href="mailto:pcreech@redhat.com" target="_blank">pcreech@redhat.com</a>><br>
>    wrote:<br>
> <br>
>      On Mon, 2018-11-19 at 17:08 -0500, Brian Bouterse wrote:<br>
>      > When we switched from UUID to integers for the PK<br>
>      > with databases other than PostgreSQL [0].<br>
>      ><br>
>      > With a goal of database agnosticism for Pulp3, if plugin writers<br>
>      plan to use bulk_create with any object inherited<br>
>      > from one of ours, they can't will get different behaviors on<br>
>      different databases and they won't have PKs that they may<br>
>      > require. bulk_create is a normal django thing, so plugin writers<br>
>      making a django plugin should be able to use it. This<br>
>      > concerned me already, but today it was also brought up by non-RH<br>
>      plugin writers also [1] in a PR.<br>
>      ><br>
>      > The tradeoffs bteween UUIDs versus PKs are pretty well summed up<br>
>      in our ticket where we discussed that change [2].<br>
>      > Note, we did not consider this bulk_create downside at that time,<br>
>      which I think is the most significant downside to<br>
>      > consider.<br>
>      ><br>
>      > Having bulk_create effectively not available for plugin writers<br>
>      (since we can't rely on its pks being returned) I<br>
>      > think is a non-starter for me. I love how short the UUIDs made our<br>
>      URLs so that's the tradeoff mainly in my mind.<br>
>      > Those balanced against each other, I think we should switch back.<br>
>      ><br>
>      > Another option is to become PostgreSQL only which (though I love<br>
>      psql) I think would be the wrong choice for Pulp from<br>
>      > what I've heard from its users.<br>
>      ><br>
>      > What do you think? What should we do?<br>
>      So, my mind immediately goes to this question, which might be<br>
>      usefull for others to help make decisions, so I'll ask:<br>
>      When you say:<br>
>      "we lost the ability to have the primary key set during bulk_create"<br>
>      Can you clarify what you mean by this?<br>
>      My mind immediately goes to this chain of events:<br>
>              When you use bulk_create, the existing in-memory model<br>
>      objects representing the data to create do not get<br>
>      updated with the primary key values that are created in the<br>
>      database.<br>
>              Upon a subsequent query of the database, for the exact same<br>
>      set of objects just added, those objects _will_ have<br>
>      the primary key populated.<br>
>      In other words,<br>
>              The database records themselves get the auto-increment IDs<br>
>      added, they just don't get reported back in that<br>
>      query to the ORM layer, therefore it takes a subsequent query to get<br>
>      those ids out.<br>
>      Does that about sum it up?<br>
> <br>
>    Yes this describes the situation, but there is a bit more to tell.<br>
>    Since PostgreSQL does return the ids the subsequent query that could be<br>
>    done to get the ids isn't written in code today. We didn't need to<br>
>    because we developed it against PostgreSQL. I'm pretty sure that if you<br>
>    configure Pulp against MySQL Pulp won't work, which I think is a<br>
>    problem. So I'm observing two things here. 1) This is a hazard that<br>
>    causes code to unexpectedly be only compliant with PostgreSQL. 2) Pulp<br>
>    itself fell into this hazard and we need to fix that too<br>
>    Do you also see these two issues? What should be done about these?<br>
> <br>
>      ><br>
>      > [0]:<br>
>      [6]<a href="https://docs.djangoproject.com/en/2.1/ref/models/querysets/#bulk-" rel="noreferrer" target="_blank">https://docs.djangoproject.com/en/2.1/ref/models/querysets/#bulk-</a><br>
>      create<br>
>      > [1]:<br>
>      [7]<a href="https://github.com/pulp/pulp/pull/3764#discussion_r234780702" rel="noreferrer" target="_blank">https://github.com/pulp/pulp/pull/3764#discussion_r234780702</a><br>
>      > [2]: [8]<a href="https://pulp.plan.io/issues/3848" rel="noreferrer" target="_blank">https://pulp.plan.io/issues/3848</a><br>
>      > _______________________________________________<br>
>      > Pulp-dev mailing list<br>
>      > [9]<a href="mailto:Pulp-dev@redhat.com" target="_blank">Pulp-dev@redhat.com</a><br>
>      > [10]<a href="https://www.redhat.com/mailman/listinfo/pulp-dev" rel="noreferrer" target="_blank">https://www.redhat.com/mailman/listinfo/pulp-dev</a><br>
>      _______________________________________________<br>
>      Pulp-dev mailing list<br>
>      [11]<a href="mailto:Pulp-dev@redhat.com" target="_blank">Pulp-dev@redhat.com</a><br>
>      [12]<a href="https://www.redhat.com/mailman/listinfo/pulp-dev" rel="noreferrer" target="_blank">https://www.redhat.com/mailman/listinfo/pulp-dev</a><br>
> <br>
>      _______________________________________________<br>
>      Pulp-dev mailing list<br>
>      [13]<a href="mailto:Pulp-dev@redhat.com" target="_blank">Pulp-dev@redhat.com</a><br>
>      [14]<a href="https://www.redhat.com/mailman/listinfo/pulp-dev" rel="noreferrer" target="_blank">https://www.redhat.com/mailman/listinfo/pulp-dev</a><br>
> <br>
>      _______________________________________________<br>
>      Pulp-dev mailing list<br>
>      [15]<a href="mailto:Pulp-dev@redhat.com" target="_blank">Pulp-dev@redhat.com</a><br>
>      [16]<a href="https://www.redhat.com/mailman/listinfo/pulp-dev" rel="noreferrer" target="_blank">https://www.redhat.com/mailman/listinfo/pulp-dev</a><br>
> <br>
>      _______________________________________________<br>
>      Pulp-dev mailing list<br>
>      [17]<a href="mailto:Pulp-dev@redhat.com" target="_blank">Pulp-dev@redhat.com</a><br>
>      [18]<a href="https://www.redhat.com/mailman/listinfo/pulp-dev" rel="noreferrer" target="_blank">https://www.redhat.com/mailman/listinfo/pulp-dev</a><br>
> <br>
> References<br>
> <br>
>    1. mailto:<a href="mailto:dkliban@redhat.com" target="_blank">dkliban@redhat.com</a><br>
>    2. <a href="https://pulp.plan.io/issues/4290" rel="noreferrer" target="_blank">https://pulp.plan.io/issues/4290</a><br>
>    3. mailto:<a href="mailto:dalley@redhat.com" target="_blank">dalley@redhat.com</a><br>
>    4. mailto:<a href="mailto:bbouters@redhat.com" target="_blank">bbouters@redhat.com</a><br>
>    5. mailto:<a href="mailto:pcreech@redhat.com" target="_blank">pcreech@redhat.com</a><br>
>    6. <a href="https://docs.djangoproject.com/en/2.1/ref/models/querysets/#bulk-create" rel="noreferrer" target="_blank">https://docs.djangoproject.com/en/2.1/ref/models/querysets/#bulk-create</a><br>
>    7. <a href="https://github.com/pulp/pulp/pull/3764#discussion_r234780702" rel="noreferrer" target="_blank">https://github.com/pulp/pulp/pull/3764#discussion_r234780702</a><br>
>    8. <a href="https://pulp.plan.io/issues/3848" rel="noreferrer" target="_blank">https://pulp.plan.io/issues/3848</a><br>
>    9. mailto:<a href="mailto:Pulp-dev@redhat.com" target="_blank">Pulp-dev@redhat.com</a><br>
>   10. <a href="https://www.redhat.com/mailman/listinfo/pulp-dev" rel="noreferrer" target="_blank">https://www.redhat.com/mailman/listinfo/pulp-dev</a><br>
>   11. mailto:<a href="mailto:Pulp-dev@redhat.com" target="_blank">Pulp-dev@redhat.com</a><br>
>   12. <a href="https://www.redhat.com/mailman/listinfo/pulp-dev" rel="noreferrer" target="_blank">https://www.redhat.com/mailman/listinfo/pulp-dev</a><br>
>   13. mailto:<a href="mailto:Pulp-dev@redhat.com" target="_blank">Pulp-dev@redhat.com</a><br>
>   14. <a href="https://www.redhat.com/mailman/listinfo/pulp-dev" rel="noreferrer" target="_blank">https://www.redhat.com/mailman/listinfo/pulp-dev</a><br>
>   15. mailto:<a href="mailto:Pulp-dev@redhat.com" target="_blank">Pulp-dev@redhat.com</a><br>
>   16. <a href="https://www.redhat.com/mailman/listinfo/pulp-dev" rel="noreferrer" target="_blank">https://www.redhat.com/mailman/listinfo/pulp-dev</a><br>
>   17. mailto:<a href="mailto:Pulp-dev@redhat.com" target="_blank">Pulp-dev@redhat.com</a><br>
>   18. <a href="https://www.redhat.com/mailman/listinfo/pulp-dev" rel="noreferrer" target="_blank">https://www.redhat.com/mailman/listinfo/pulp-dev</a><br>
<br>
> _______________________________________________<br>
> Pulp-dev mailing list<br>
> <a href="mailto:Pulp-dev@redhat.com" target="_blank">Pulp-dev@redhat.com</a><br>
> <a href="https://www.redhat.com/mailman/listinfo/pulp-dev" rel="noreferrer" target="_blank">https://www.redhat.com/mailman/listinfo/pulp-dev</a><br>
<br>
<br>
-- <br>
Simon Baatz <<a href="mailto:gmbnomis@gmail.com" target="_blank">gmbnomis@gmail.com</a>><br>
</blockquote></div>