SQL Server 2017 – CU25 – sp_pkeys – Wrong order

After our customers have installed CU25 there is a problem with the stored procedure sp_pkeys. It may now return the wrong order if a primary key has multiple columns.

It can be tracked down in the code itself. This is the 2017 CU25 variant:

create procedure sys.sp_pkeys (     @table_name      sysname,     @table_owner     sysname = null,     @table_qualifier sysname = null ) as     declare @table_id           int     -- quotename() returns up to 258 chars     declare @full_table_name    nvarchar(517) -- 258 + 1 + 258          if @table_qualifier is not null     begin         if db_name() <> @table_qualifier         begin   -- If qualifier doesn't match current database             raiserror (15250, -1,-1)             return         end     end          if @table_owner is null     begin   -- If unqualified table name         select @full_table_name = quotename(@table_name)     end     else     begin   -- Qualified table name         if @table_owner = ''         begin   -- If empty owner name             select @full_table_name = quotename(@table_owner)         end         else         begin             select @full_table_name = quotename(@table_owner) + '.' + quotename(@table_name)         end     end          select @table_id = object_id(@full_table_name)          select         TABLE_QUALIFIER = convert(sysname,db_name()),         TABLE_OWNER = convert(sysname,schema_name(o.schema_id)),         TABLE_NAME = convert(sysname,o.name),         COLUMN_NAME = convert(sysname,c.name),         KEY_SEQ = (SELECT convert(smallint, index_column_id)                              FROM sys.index_columns                               WHERE object_id = @table_id AND index_id = i.index_id and column_id = c.column_id),         PK_NAME = convert(sysname,k.name)     from         sys.indexes i,         sys.all_columns c,         sys.all_objects o,         sys.key_constraints k     where         o.object_id = @table_id and         o.object_id = c.object_id and         o.object_id = i.object_id and         k.parent_object_id = o.object_id and          k.unique_index_id = i.index_id and          i.is_primary_key = 1 and               c.column_id IN                (SELECT column_id                FROM sys.index_columns                WHERE object_id = @table_id AND index_id = i.index_id)     order by 1, 2, 3, 5 

And this is the SQL Server 2017 CU24 and SQL Server 2019 variant:

create procedure sys.sp_pkeys   (       @table_name      sysname,       @table_owner     sysname = null,       @table_qualifier sysname = null   )   as       declare @table_id           int       -- quotename() returns up to 258 chars       declare @full_table_name    nvarchar(517) -- 258 + 1 + 258          if @table_qualifier is not null       begin           if db_name() <> @table_qualifier           begin   -- If qualifier doesn't match current database               raiserror (15250, -1,-1)               return           end       end          if @table_owner is null       begin   -- If unqualified table name           select @full_table_name = quotename(@table_name)       end       else       begin   -- Qualified table name           if @table_owner = ''           begin   -- If empty owner name               select @full_table_name = quotename(@table_owner)           end           else           begin               select @full_table_name = quotename(@table_owner) + '.' + quotename(@table_name)           end       end          select @table_id = object_id(@full_table_name)          select           TABLE_QUALIFIER = convert(sysname,db_name()),           TABLE_OWNER = convert(sysname,schema_name(o.schema_id)),           TABLE_NAME = convert(sysname,o.name),           COLUMN_NAME = convert(sysname,c.name),           KEY_SEQ = convert (smallint,               case                   when c.name = index_col(@full_table_name, i.index_id,  1) then 1                   when c.name = index_col(@full_table_name, i.index_id,  2) then 2                   when c.name = index_col(@full_table_name, i.index_id,  3) then 3                   when c.name = index_col(@full_table_name, i.index_id,  4) then 4                   when c.name = index_col(@full_table_name, i.index_id,  5) then 5                   when c.name = index_col(@full_table_name, i.index_id,  6) then 6                   when c.name = index_col(@full_table_name, i.index_id,  7) then 7                   when c.name = index_col(@full_table_name, i.index_id,  8) then 8                   when c.name = index_col(@full_table_name, i.index_id,  9) then 9                   when c.name = index_col(@full_table_name, i.index_id, 10) then 10                   when c.name = index_col(@full_table_name, i.index_id, 11) then 11                   when c.name = index_col(@full_table_name, i.index_id, 12) then 12                   when c.name = index_col(@full_table_name, i.index_id, 13) then 13                   when c.name = index_col(@full_table_name, i.index_id, 14) then 14                   when c.name = index_col(@full_table_name, i.index_id, 15) then 15                   when c.name = index_col(@full_table_name, i.index_id, 16) then 16               end),           PK_NAME = convert(sysname,k.name)       from           sys.indexes i,           sys.all_columns c,           sys.all_objects o,           sys.key_constraints k       where           o.object_id = @table_id and           o.object_id = c.object_id and           o.object_id = i.object_id and           k.parent_object_id = o.object_id and            k.unique_index_id = i.index_id and            i.is_primary_key = 1 and           (c.name = index_col (@full_table_name, i.index_id,  1) or            c.name = index_col (@full_table_name, i.index_id,  2) or            c.name = index_col (@full_table_name, i.index_id,  3) or            c.name = index_col (@full_table_name, i.index_id,  4) or            c.name = index_col (@full_table_name, i.index_id,  5) or            c.name = index_col (@full_table_name, i.index_id,  6) or            c.name = index_col (@full_table_name, i.index_id,  7) or            c.name = index_col (@full_table_name, i.index_id,  8) or            c.name = index_col (@full_table_name, i.index_id,  9) or            c.name = index_col (@full_table_name, i.index_id, 10) or            c.name = index_col (@full_table_name, i.index_id, 11) or            c.name = index_col (@full_table_name, i.index_id, 12) or            c.name = index_col (@full_table_name, i.index_id, 13) or            c.name = index_col (@full_table_name, i.index_id, 14) or            c.name = index_col (@full_table_name, i.index_id, 15) or            c.name = index_col (@full_table_name, i.index_id, 16))                   order by 1, 2, 3, 5 

The crucial part is how KEY_SEQ is determined. It would work correctly if the second variant would be used.

Alternatively even the first variant would work if the sub-select would be done like this:

SELECT convert(smallint, key_ordinal) FROM sys.index_columns  WHERE object_id = @table_id AND index_id = i.index_id and column_id = c.column_id 

So key_ordinal instead index_column_id needs to be used.

However as it is a system stored procedure it seemingly is not possible to change it. At least not without very critical and unadvised steps.

Are there any alternatives than downgrading or waiting for a fix from Microsoft (workarounds)? What would be the best way to contact Microsoft to receive a fix as quickly as possible?

Edit: Forgot to mention. They even have written about a change to sp_pkeys in their release notes. See https://support.microsoft.com/en-us/topic/kb5003830-cumulative-update-25-for-sql-server-2017-357b80dc-43b5-447c-b544-7503eee189e9#bkmk_13975159.

Edit2: There is no difference with CU26 which was just released.

Save product short description in order (without updating in order details if it is updated in product)

I understand that it is possible to display the short description of the product on the order details page, even in an email. But I need this not to update when I update the short product description.

Real situation: My products are updated every day, these products detail the number of parts that will actually be sent at the time of purchase, according to availability.

Title: Surprise box

Short description: Contains a palette, a lemon and a stone. (this changes every day)

I need to pass this short description in the mail, order details for the client and for the admin, so I can follow up later.

The problem is that I only find codes to show the short description of the updated product, no matter the time of purchase, the last one edited will always be shown.

any idea where to start?

wp_insert_post order problem

I’m sorry, I speak a little English.

My code in my custom theme (functions.php) [only example]:

$  posts = array( '141th', // ... '3rd', '2nd', '1st' ); foreach( $  posts as $  post ) { wp_insert_post( array( 'post_title'=> $  post ) ); } 

My posts list:

141 139 140 137 138 ... 1 

I would like (in order):

141 140 139 138 ... 1 

Why? What is the problem and how to solving?

Thanks.

What’s the default order used by WordPress to load CSS files?

I am working with a commercial theme on which I am making some style changes. Specifically, the parent theme shows a menu which I want to modify. The code for that menu is:

 <div class="mobile-navigation hidden-md hidden-lg">         <div id="close-menu-moblie">             <a href="#">                 <i class="icon-close icons"></i>             </a>         </div>    <div class="mobile-menu-container">         <ul id="menu-menu-movil" class="nav-menu mobile-menu">             <li id="menu-item-4723" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-4723 active">                 <a href="/" aria-current="page">La Familia</a>             </li>             <li id="menu-item-4724" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-4724">                 <a href="/tierras.html">La Tierra</a>             </li> 

So I created a child theme and added some CSS to it in its style.css file:

#menu-menu-movil li > a {     font-weight: 500;     font-family: Poppins, Arial, sans-serif;     } 

No way: the site ignores my changes. When I inspect the HTML I see that the browser is applying instead CSS instructions from the parent theme that target different classes:

.mobile-navigation .nav-menu > li > a {     font-size: 16px;     color: #1a1a1a;     font-weight: bold;     text-transform: capitalize; } 

So I think that it’s a problem with conflicting CSS instructions and their level of specificity or whatever… but then I try opening the CSS editor in WP Admin at "Appearance / Customise / Additional CSS" and pasting there my changes… and they work.

This led me to think: is there a default order in which WordPress loads CSS from all the possible places where they can be? ("Additional CSS", child themes, parent themes…). I seem to remember that there was, but after searching around on Google for a while I couldn’t find anything. Or is my problem in the end about CSS specificity?

Several Postgres partitioning questions (hierarchical partitioning, HASH, PK order)

I’m pretty new to Postgres. I have a few related questions about the performance benefits of partitioning.

Background: I am trying to fix slow batch queries on a 4 column table with over 300 million rows. The PK is on all columns and the 3 columns that aren’t at the beginning of the PK also have single column indexes.

The indexes are growing out of control and are collectively larger than all RAM, and 3x the size of the underlying data. Batches regularly read and write a couple hundred million rows and they are slow.

What I have already done/understand: I’ve analyzed the code and determined that only the first and last columns are used in SELECT WHERE clauses. Other than INSERTs, no other queries hit this table (besides a DELETE that will be replaced with partition dropping). So I already know I can drop two of the three indexes since they are unused, which will lead to reduced index size, fewer indexes, and hopefully improved INSERT/SELECT performance.

In addition to dropping the unused indexes, I am going to use partitioning to replace a lengthy DELETE statement (which has a WHERE on the two middle columns) with, instead, LIST partitioning on those columns so I can DROP partitions.

Where I have questions: My proposed LIST partition also breaks up the table somewhat, so the partitions are no more than 1/4 the size of the original table. However, even that size is very large. I am considering adding a second hierarchical partition layer with a HASH partition on the 4th column, which could further considerably reduce partition size. My hope is that this would further reduce RAM consumption and/or improve performance in other ways.

However, I have a few questions about this:

  1. While I would be reducing partition size, my queries actually select on nearly every value in the column where I would be using HASH partitioning. I don’t know the distribution of those selected values, so there might be hot and cold partitions, but few totally cold partitions. In this case, would HASH partitioning even help, or would it be no improvement over the single level of partitioning? It’s kind of confusing to me, because since hashing is random by design, I would expect this to be a problem whenever HASH is used.

The only reason I think it might help is by reducing the height of the index trees, since the indexes exist within partitions. But all indexes would still be used. Basically what I’m wondering is, is it still an improvement to reduce index height even if all the indexes may be used, versus one huge index? Is there a best practice as to when HASH might help?

  1. The upper level of the partition hierarchy is a LIST on the two middle columns because that’s how my DELETE (that I am replacing) is defined. But those columns are never used in WHERE clauses. Is it a problem if the top partition hierarchy level isn’t even used in WHERE clauses? I could reverse the order so the HASH is the parent partition, since I actually select by that, but then I’d need to drop multiple partitions when I DROP. Should I just bite the bullet and switch the order?

  2. Is it best for the order of the partition hierarchy to match the order of the PK? In other words, if my parent partitioning is LIST(col2, col3) and my child partitioning is HASH(col4), should I change my PK from 1,2,3,4 to 2,3,4,1 to match, or does it not matter?

What conditions must be met in order to upload .zip file to a multisite WordPress installation?

I cannot upload .zip files to my WordPress network, despite making IMHO everything that is needed. I am still hit by this irritating error.

enter image description here

Details:

  1. I am a super-admin in my network.
  2. The ALLOW_UNFILTERED_UPLOADS flag is set to true
  3. Custom hook of $ existing_mimes['zip'] = 'application/zip'; is added
  4. Uploading .zip files is allowed in my network:

enter image description here

Here is entire code of my hook:

function so_387865_custom_upload_mimes ( $  existing_mimes ) {     $  existing_mimes['epub'] = 'application/epub+zip';     $  existing_mimes['mobi'] = 'application/x-mobipocket-ebook';     $  existing_mimes['zip'] = 'application/zip';       return $  existing_mimes; }   add_filter('upload_mimes', 'so_387865_custom_upload_mimes'); 

I thought that maybe there’s something wrong with the hook, so I have installed the Enhanced Media Library extension (as suggested in here). All for nothing, as it clearly shows that this MIME type is added:

enter image description here

What else should I do in order to be able to upload .zip files? I am seriously lost!

Need help with my risk game program – i need to insert 2 players, throw x number of dices, order them and confront the results of the 2 players

using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Text;

namespace ConsoleApp8 { class Program { static List names; static List dices; // [2, 3] static List player1Dices = new List(); static List player2Dices = new List();

    static List<string> PromptNames()     {         Console.Write("Nome del primo giocatore: ");         string player1 = Console.ReadLine();         Console.Write("Nome del secondo giocatore: ");         string player2 = Console.ReadLine();          List<string> names = new List<string>();          names.Add(player1);         names.Add(player2);         return names;     }      static int GetDieValue(string x, string msg)     {         Console.Write("{0}, {1} ", x, msg);         string rawDie = Console.ReadLine();         int parsedDie;         // qui devi usare do, while perché non sai a priori quante volte un giocatore potrebbe inserire un valore sbagliato         if (!Int32.TryParse(rawDie, out parsedDie))         {             Console.WriteLine("Meti un numero");             return GetDieValue(x, msg);         }         return parsedDie;     }      static List<int> PromptDices()     {         int p1Dices = GetDieValue(names[0], "con quanti dadi vuoi attaccare?");         int p2Dices = GetDieValue(names[1], "con quanti dadi ti vuoi difendere?");          return new List<int>() { p1Dices, p2Dices };     }     static void Play()     {         Console.WriteLine("{0} attacca con {1} dadi", names[0], dices[0]);         Console.WriteLine("{0} difende con {1} dadi", names[1], dices[1]);         CalculateResult();      }     static void CalculateResult()     {         System.Random random = new System.Random();         for (int i = 0; i <= dices.Count; i++)         {             player1Dices.Add(random.Next(1, 7));         }         Console.WriteLine("Prima: {0}{1}{2}", player1Dices[0], player1Dices[1], player1Dices[2]);         player1Dices = player1Dices.OrderByDescending(x => x).ToList();         Console.WriteLine("Dopo: {0}{1}{2}", player1Dices[0], player1Dices[1], player1Dices[2]);           for (int i = 0; i <= dices.Count; i++)         {             player2Dices.Add(random.Next(1, 7));         }         Console.WriteLine("Prima: {0}{1}{2}", player2Dices[0], player2Dices[1], player2Dices[2]);         player2Dices = player2Dices.OrderByDescending(x => x).ToList();         Console.WriteLine("Dopo: {0}{1}{2}", player2Dices[0], player2Dices[1], player2Dices[2]);      }         private static void PlayAgain(string x)     {         Console.WriteLine("Se vuoi finire il gioco scrivi Exit");         string Exit = x;         do         {             RunGame();             player1Dices.Clear();             player2Dices.Clear();         }         while (x != Console.ReadLine());                }      static void RunGame()     {         names = PromptNames();         dices = PromptDices();         CalculateResult();         Play();         PlayAgain();                          // generate random numbers - and sort them         // display results - compare dices         // repeat or quit?     }      private static void PlayAgain()     {         throw new NotImplementedException();     }      static void Main(string[] args)     {         RunGame();         Console.WriteLine("Thanks for playing");         Console.ReadKey();     } } 

}

How to add the item price in the review order section of the checkout page

I have this code that adds an items "each" price in the review order section of the checkout page, which is what i want.

However, it also adds it to the cart page, which i do not want.

How can i update this code to make sure the individual price does not show on the cart page?

<?php 

add_filter( ‘woocommerce_cart_item_name’, ‘showing_price_in_cart_items’, 99, 3 ); function showing_price_in_cart_items( $ item_name, $ cart_item, $ cart_item_key ) { // The WC_Product object $ product = $ cart_item[‘data’];

if (empty($  product)) {     return $  item_name; }  // Get the  price $  price = $  product->get_price();  // When price doesn't exist if (empty($  price)) {     return $  item_name; }  // display the price $  item_name .= '<br><small class="product-price">' . __( "£$  price each: ", "woocommerce") . $  price . '</small>';  return $  item_name; 

}